51)Write a C program to store an array element using selection sort method.


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5]={15,7,2,32,12};
int i,j,k=0,l,t=0;
clrscr();
printf(“\n Before sorting:-\n”);
for(i=0;i<5;i++)
printf(“%d\n”,a[i]);
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
k=j;
for(l=j+1;l<5;l++)
{
if(a[l]<a[k])
{
k=l;
}
t=a[j];
a[j]=a[k];
a[k]=t;
}
}
}
printf(“\n Sorted list:-\n”);
for(i=0;i<5;i++)
{
printf(“%d\n”,a[i]);
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s