Completely Solved C, C++ Programs Assignment.




C Program to sort the entered elements using selection sort technique.

Filed Under:

Problem 73. C Program to sort the entered elements using selection sort technique.
#include<stdio.h>
#include<conio.h>
main( )
{
int a[100],i,n,j,t,min,pos;
clrscr();
printf(“enter the array size”);
scanf(“%d”,&n);
printf(“enter the elements”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
{
min=a[i];
pos=i;
for(j=0;j<n-1;j++)
if(min>a[j])
{
min=j;
pos=j;
}
t=a[i];
a[i]=a[pos];
a[pos]=t;
}
printf(“the sorted elements are”);
for(i=0;i<n;i++)
printf(“%2d”,a[i]);
getch( );
}

C compiler: gcc 4.1.2

 Back to main directory: Sample C Program | Software Practical | Solved C Assignment


Get Free Programming Tutorials and Solved assignments