/* Selection Sort */
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]={23, 15, 29, 11, 1};
int i,j,temp;
clrscr();
printf(" Selection Sort ");
printf("\n Array before Sorting : \n");
for(i=0;i<=4;i++)
printf("%d\t",arr[i]);
for(i=0;i<=3;i++)
{
for(j=i+1;j<=4;j++)
{
if(arr[i] > arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\n\n Array after Sorting : \n");
for(i=0;i<=4;i++)
printf(" %d\t",arr[i]);
getch();
}
No comments:
Post a Comment