/*****************<soeasyprograms.blogspot.in>******************/
/* program to sort the list of numbers using bubble sort */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,c,a[100];
clrscr();
printf("\n Enter how many numbers you want to sort");
scanf("%d",&n);
printf("\n Enter array elements");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Before sorting array elemnts are");
for(i=1;i<=n;i++)
{
printf("\n %d",a[i]);
}
for(i=1;i<=n-1;i++) /* for no of passes*/
{
for(j=1;j<=n-i;j++) /*for no of comparison in each pass*/
{
if(a[j]>a[j+1]) /*comaprison*/
{
c=a[j];
a[j]=a[j+1];
a[j+1]=c;
}
}
}
printf("\n\n After sorting array elemnts are");
for(i=1;i<=n;i++)
{
printf("\n %d",a[i]);
}
getch();
}
/*****************<soeasyprograms.blogspot.in>******************/
No comments:
Post a Comment