Thursday, November 17, 2016

Program To sort numbers using C

C Program has so many wonderful features.It Can sort data.Here is the following code::

#include<stdio.h>
#include<conio.h>
void main()
{
int a[22],i,j,k;
clrscr();
for(i=1;i<=5;i++)
scanf("%d",a[i]);


for(i=1;i<=5;i++)
{

for(j=1;j<=5-i;j++)
{

if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
printf("\n\n\nThe output is:");
for(i=1;i<=5;i++)
printf("%4d",a[i]);
getch();
}


Hope this code will help you to understand the bubble sorting well.thank u guys.


No comments:

Post a Comment