Write a Program in C to Sort a Set of Number using Bubble Sort
#include <stdio.h>
#include <conio.h>
void main()
{
int a[100],i,j,n,t;
clrscr();
printf("\nEnter Number Of Elements:");
scanf("%d", &n);
printf("\nEnter the Elements:");
for (i=0;i<n;i++)
{
printf("\nEnter Element number %d:", i+1);
scanf("%d", &a[i]);
}
for (i=0;i<n-1;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 array is: \n");
for (i=0;i<n;i++)
printf("%d ", a[i]);
getch();
}
Comments
Post a Comment