You are on page 1of 2

BUBBLE SORTING

#include<stdio.h>
#include<conio.h>

int main()
{
int a[5],n,i,j,k,temp;
//clrscr();
printf("\n\tEnter n value: ");
scanf("%d",&n);
printf("\n\tEnter numbers: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n\tNumbers are: ");
for(i=0;i<n;i++)
printf("\t%d",a[i]);
printf("\n\n");

for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
printf("\t");
if(a[i]<a[j])
//if(a[i]>a[j])

// Descending Order
// Ascending Order

{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
// For Analysis
for(k=0;k<n;k++)
printf("%d\t",a[k]);
printf("\n\n");
}
}

printf("\nBUBBLE SORT RESULT\n\n\t\t");


for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
return 0;
}