Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements “bubble” to the top of the list.
Language : C
[sourcecode language='c']
//Bubble Sort
#include
void main()
{
int a[100],temp,j,i,n;
printf(“Enter the value for n :”);
scanf(“%d”, &n);
for(i=0;i
{ printf(“Enter the value for the %d element :”, i+1);
scanf(“%d”, &a[i]);
}
for(i=0;i
{
for(j=0;ja[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf(“The sorted array is : “);
for(i=0;i
{ printf(“\n%d”, a[i]);
}
}
[/sourcecode]






