#include<stdio.h>
#include<conio.h>
void selectionSort(int a[],int n);
int main ()
{
int n,i,a[10];
clrscr();
printf("How many no you want to enter: ");
scanf("%d",&n);
printf("Enter the no:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
selectionSort(a,n);
printf("After Selection Sorting:\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
return 0;
}
void selectionSort(int a[],int n)
{
int i,j,min,index;
for(i=0;i<n;i++)
{
min=a[i];
index=i;
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
index=j;
}
}
if(index!=i)
a[i]=(a[i]+a[index])-(a[index]=a[i]);
}
}
Related posts: