EmbLogic's Blog

write a program for selection sort

#include<stdio.h>

int main()
{
int a[5];
int i,j,loc,smallest,temp;
printf(“enter array element”);
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
for(j=0;j<5;j++)
{
smallest=a[j];
for(i=j+1;i<5;i++)
{
if(a[i]<smallest)
{
smallest=a[i];
loc=i;
temp=a[j];
a[j]=a[loc];
a[loc]=temp;

}

}
printf(“sorted array is[%d]=%d\n”,j,a[j]);
}
return 0;
}

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>