Professional Documents
Culture Documents
C program for bubble sort: c programming code for bubble sort to sort numbers or arrange them
in ascending order. You can easily modify it to print numbers in descending order.
( n - 1 ); c++)
< n - c - 1; d++)
> array[d+1]) /* For decreasing order use < */
= array[d];
= array[d+1];
= swap;
Output of program:
return 0;
}
}
t
= list[d];
list[d]
= list[d+1];
list[d+1] = t;
return 0;
}
#include<stdio.h>
#include<conio.h>
int main( )
{
int a[100];
int i, j, temp, n ;
printf("how many numbers you want to sort : \n");
scanf("%d",&n);
printf("Enter %d number values you want to sort\n", n);
for(j=0; j<n; j++)
scanf("%d",&a[j]);
for(j=1;j<n;j++)
{
for(i=0; i<n; i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf ( "\n\nArray after sorting:\n") ;
for ( i = 0 ; i <n ; i++ )
printf ( "%d\t", a[i] ) ;
getch();
}