132. Program to arrange array in ascending order using selection sort.
#include<stdio.h>
int
a[5]={1,20,5,12,3},ele,i,t,j;
void
main()
{
ele=sizeof(a)/sizeof(a[0]);
printf("\n");
for(i=0;i<ele;i++)
printf("%d ",*(a+i));
printf("\n");
for(i=0;i<ele-1;i++)
{
for(j=1+i;j<ele;j++)
{
if(a[i]>a[j])
{
a[i]=a[i]^a[j];
a[j]=a[i]^a[j];
a[i]=a[i]^a[j];
}
}
printf("\n");
}
printf("\n");
for(i=0;i<ele;i++)
printf("%d ",*(a+i));
}
Comments
Post a Comment