Monday, 21 October 2013

Program In C For Selection Sort In An Array

#include<stdio.h>
#include<conio.h>
int min(int a[ ],int n,int k)
{ int small,loc,j;
small=a[k];
loc=k;
for(j=k+1;j<=n;j++)
{ if(small>a[j])
{ small=a[j];
loc=j; } }
return loc; }
void main()
{ int a[10],n,k,loc,i,temp;
clrscr();
printf("Enter The Size Of Array: ");
scanf("%d",&n);
printf("\nEnter Array: ");
for(i=1;i<=n;i++)
{ scanf("%d",&a[i]); }
for(k=1;k<n;k++)
{ loc=min(a,n,k);
temp=a[k];
a[k]=a[loc];
a[loc]=temp;
}
printf("Array After Sorting Is: ");
for(i=1;i<=n;i++)
{ printf("%d\t",a[i]); }
getch();
}

No comments:

Post a Comment