// C program to sort an array using bubble sort.
// Bubble sort in c.
#include<stdio.h>#include<conio.h>
void main()
{
int a[10],i,n,j,temp;
clrscr();
printf("Enter the limit\n");
scanf("%d",&n);
printf("Enter the %d array elements\t",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++) // bubble sorting begins here
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("sorted array is as follows\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}
Related post: Bubble sort in c++