Social Icons

Sunday, 16 February 2014

Program to sort an Array using Bubble sort

#include<stdio.h>
#include<conio.h>

void main()
{
int a[50],n,i,j,temp;
clrscr();
printf("\n Enter the size of array : ");
scanf("%d",&n);
printf("\n Enter elements : ");
for(i=0;i<n;++i)
scanf("%d",&a[i]);

for(i=1;i<n;++i)
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}

printf("\n\t Array after sorting : ");
for(i=0;i<n;++i)
printf("%d ",a[i]);
getch();
}


                                                       Output

No comments:

Post a Comment