Program to sort the entered numbers using bubble sort - 100 Most Important C# Programs

100 Most Important C# Programs

48. Program to sort the entered numbers using bubble sort.

Code:

# include <stdio.h>

# include <conio.h>

main( )

{

int a[100],i,j,n,t;

clrscr( );

printf(“enter the array size”);

scanf(“%d”,&n);

for(i=1;i<n;i++)

scanf(“%d”,&a[i]);

for(i=1;i<=n;i++)

for(j=i+1;j<n;j++)

if(a[i]>a[j])

{

t=a[i]

a[i]=a[j];

a[j]=t;

}

printf(“the sorted elements are “);

for(i=1;i<=n;i++)

print(“%d”,a[i]);

getch( );

}