My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.

Monday, 15 August 2011

Sort Using Selection Sort

Write a Program in C to Accept 5 Numbers from the User and Sort Using Selection Sort
#include<stdio.h>
#include<conio.h>
void main()
{
int swap,i,j,num[10],k;
clrscr();
printf("Enter 5 numbers\n\n");
for(i=0;i<=4;i++)
{
scanf("%d",&num[i]); //Accepting 5 numbers
}
printf("\n\n Original Nos. \t\t\t");
for(k=0;k<=4;k++)
{
printf("%d\t",num[k]); //printing the numbers
}
printf("\n\n");
for(i=0;i<=3;i++)
{
printf("Round %d \n",i+1);
for(j=i+1;j<=4;j++)
{
printf("Comapring (%d) and (%d)",i+1,j+1);
if(num[i]>num[j])
{
swap=num[i];
num[i]=num[j];
num[j]=swap;
}
printf("\t\t");
for(k=0;k<=4;k++)
{
printf("%d\t",num[k]); //printing the numbers
}
printf("\n");
getch();
}
printf("\n");
}
printf("\n\nNumbers after using Selection Sort Method\n");
for(i=0;i<=4;i++)
{
printf("%d\n",num[i]);
}
getch();
}

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls