Apr 16, 2013

C program to sort numbers using bubble sort


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,temp=0;
clrscr();
for(i=0;i<=4;i++)
{
printf("enter (%d) no=",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<=4;i++)
{
printf("%d\n",a[i]);
}
getch();
}

OUTPUT


enter (1) no=9
enter (2) no=5 
enter (3) no=42 
enter (4) no=6 
enter (5) no=2 




42





0 comments:

Post a Comment