Write a C program to implement Bubble sort.
#include<stdio.h>
main()
{
int n,i,a[30],temp,j;
printf("\n\n\t\tBUBBLE
SORT\n");
printf("\t\t**************\n");
printf("\nEnter the Number of
Terms :\n\n");
scanf("%d",&n);
printf("\n Enter the
Value:\n\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n BEFORE
SORTING\n\n");
for(i=0;i<n;i++)
printf("%5d",a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\n AFTER
SORTING\n");
for(i=0;i<n;i++)
printf("%5d",a[i]);
getch();
}
0 comments:
Feel free to contact the admin for any suggestions and help.