/* C code to implement Selection Sort technique */
#include<stdio.h>
int main()
{
int n, i, a[50], j, temp, min;
printf("Enter n");
scanf("%d",&n);
printf("Enter any %d
values",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
/* Logic for Selection Sort Begins */
for(i=0;i<n;i++)
{
min=i;
for(j=i+1;j<n;j++)
{
if (a[min]>a[j])
min=j;
}
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
printf("\n Sorted Values are
\n");
for(i=0;i<n;i++)
{
printf("\n %d",a[i]);
}
return(0);
}
No comments:
Post a Comment