WAP in C for implementation of selection sorting?

#include<stdio.h>
#include<conio.h>
#define N 100
int main()
{
int a[N],n,i,j,min,index;
clrscr();
printf(“\nEnter the size of array”);
scanf(“%d”,&n);
printf(“\nEnter the element of array”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
{
min=a[i];
index=i;
for(j=i+1;j<n;j++)
{
if(min>a[j])
{
min=a[j];
index=j;
}
}
a[index]=a[i];
a[i]=min;
}
printf(“Sorted element:\n”);
for(i=0;i<n;i++)
printf(“\t%d”,a[i]);
getch();
return(0);
}

Output :-

s30

Advertisements

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