Professional Documents
Culture Documents
Array Sorting Program (Bubble Sort)
Array Sorting Program (Bubble Sort)
#include<stdio.h>
int main()
{
int a[5]={5,4,3,2,1};
int i;
int j;
int temp;
for(i=5;i>1;i--)
{
for(j=0;j<(i-1);j++) // i-1 condition is because the numbers
already shifted
// to right doesn't need to be compared
again
{
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
return 0;