EmbLogic's Blog

c program for selection sort.

#include
int main()
{
int a[100],i,j,small,n,k;
printf(“Enter size of array:”);
scanf(“%d”,&n);
printf(“Enter element:\n”);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);

}
printf("Element and their position are:\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
for(i=0;i<n;i++)
{
small=i;
for(j=i;j<n;j++)
{
if(a[j]<a[small])
small=j;
}
k=a[small];
a[small]=a[i];
a[i]=k;
}
printf("Arrar after selection sort:\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>