BUBBLE SORT PROGRAM

BUBBLE SORT
#include<stdio.h>
#include<conio.h>
BUBBLE SORT PROGRAM

void main()
{
int i, j, n, a[10],temp;
clrscr();

printf("\n Enter the n value: ");
scanf("%d",&n);

printf("\n Enter the %d array elements", n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);

for(i=1;i<=n-1;i++)
{
           for(j=1;j<=n-i;j++)
           {
                       if(a[j]>a[j+1])
                       {
                       temp=a[j];
                       a[j]=a[j+1];
                       a[j+1]=temp;
                       }
           }
}

printf("\n After sorting the elements are: ");
for(i=1;i<=n;i++)
printf("%3d",a[i]);

getch();
}
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment