WAP to sort an array using selection sort

#include<stdio.h>
 #include<stdlib.h>

 int main()
 {
 int a[10],i,j,t;
 printf("entar ten elements to be sorted");
for(i=0;i<=9;i++)
 scanf("%d",&a[i]);
for(i=0;i<=8;i++)
 {
 for(j=i+1;j<=9;j++)
 {
 if(a[i]>a[j])   //ascending order
 {
 t=a[i];
 a[i]=a[j];
 a[j]=t;
 }
 }}
for(i=0;i<=9;i++)
 {
 printf("%d\t",a[i]);
}
 printf("\n");
system("PAUSE");
 }

Leave a comment

Filed under TUTORIALS

Leave a comment