- WAP to sort an array with Selection Sort technique(Ascending Oder)
#include <conio.h>
void main()
{
int a[10],i,j,c;
printf("Enter the array element");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
c=i;
for(j=i+1;j<10;j++)
{
//Ascending Order
if(a[i]>a[j])
c=j;
}
a[i]=(a[i]+a[c])-(a[c]=a[i]);//one line swapping
}
printf("The sorted array is:");
for(i=0;i<10;i++)
printf("%d ",a[i]);
}
No comments:
Post a Comment