BUBBLE SORT PROGRAM

 BUBBLE SORT PROGRAM

#include<stdio.h>
void main()
{
int n, i, j, temp, a[100];
printf("Enter the value for n ");
scanf("%d",&n);
printf("Enter %d elements into array\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The unsorted array is\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
for(i=1;i<n;i++)
{
for(j=0;j<(n-i);j++)
{

if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\nThe sorted array is\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}

Comments