Write a Program that implement selection sort, to sort a given list of integers in ascending order

 /* Write a Program that implement selection sort, to sort a given list of integers in ascending order */


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int a[10],i,j,n,temp;

printf(" enter no of array elements : \n");
scanf("%d",&n);

printf(" enter unsorted %d elements  \n",n);

for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)

{

for(j=i+1;j<=n;j++)

{
if(a[i] > a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}

}

}
printf("sorted array after selection sort : \n");

for(i=1;i<=n;i++)
{
printf("\n  %d ", a[i]);
}
getch();
}

Comments

Popular posts from this blog