Hi friends,
Here I'm posting a C program implementing Selection sort. It is specially dedicated to S1 S2 B tech students because Selection sort is one of the most frequently asking questions in "Computer Programming" exams. Hope this will be Useful 4 you.!!! :)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,j,temp,a[50];
printf("\nEnter how many elements=");
scanf("%d",&n);
printf("\nEnter %d elements",n);// Input the elements
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)// Sorting the elements
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
printf("\nSorted Array:\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
2 comments :
Nice explanation Hitesh Kumar :)
Post a Comment