Thursday, July 30, 2009

bubble sort using c language

//program to sort the elements using bubble sort
#include
#include
void main()
{
int a[10],n,i,j,temp;
clrscr();

printf("\nEnter the num of elements in the array:");
scanf("%d",&n);
printf("\nEnter the elements into the array");
flushall();
for(i=0;i scanf("%d",&a[i]);

for(i=0;i {
for(j=0;j if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
printf("the numbers after sorting are:");
for(i=0;i printf("%d ",a[i]);
getch();

}

No comments:

Post a Comment