Ads Top

Bubble sort program using c

Bubble sort ,program ,using c,practicals,lab,computer

Bubble sort program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,a[20],t;
clrscr();
printf("Enter the number of elements in array");
scanf("%d",&n);
printf("Enter the array elements:\n");
printf("\n The array is:");
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>=a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}

printf("The sorted elements are:\n ");
for(i=0;i<n;i++)
{
printf("\n %d",a[i]);
}
getch();
}

Output

Enter the number of elements in   array :5
Enter the array elements:
12
15
20
18
10
Sorted elements are:
10
12
15
18
20

No comments:

Touchfeeds. Powered by Blogger.