//Selection Sorting
#include<stdio.h>
#include<conio.h>
void
main()
{
//Declaration of Variables
int a[100],n,i,j,pos,temp;
clrscr();
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d integers\n",n);
//Entry of number of elements as per user
choice
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<(n-1);i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(a[pos]>a[j])
pos=j;
}
if(pos!=i)
{
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
}
printf("After Sorting the list is\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.