7) Sort the given set of n numbers using bubble sort.
/*To sort n values using bubble sort in ascending order*/
#include<stdio.h>
int main()
{
int n, a[20], i, j, temp;
/* Accepting input */
printf("Hown many numbers?\n");
scanf("%d",&n);
printf("Enter %d numbers: \n",n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("Numbers before sorting: \n");
for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
/*Bubble sort begins*/
for(i=0; i<n; i++)
{
for(j=0;j <n-i-1; j++)
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
printf("\n After sorting: \n");
for(i=0; i<n; i++)
{
printf("%3d",a[i]);
}
}