Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Bubble Sorting in C Language




In this C program we will sort(in ascending order) some elements and print the sorted order of the Array of elements, in the screen. The Number of elements to be entered in the Array will be taken from the user and also the values of the elements.color>

input:

The number of elements(integers) (i.e. 5,10,7 etc.) & the values of the elements(integers) (i.e. 51,10,74 etc.).

output:

The sorted(in Ascending Order) numbers will be printed on the screen.

CODE---->



#include
int main()
{
int a[50],n,i,j,t;
printf(" Please, Enter the Number of Elements : ");
scanf("%d",&n);
for(i=0;in;i++)
{
printf("\n Please, Enter data : ");
scanf("%d",&a[i]);
}
for(i=0;in-1;i++)
{
for(j=0;jn-i-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\n After sorting : ");
for(i=0;in;i++)
printf("%d ",a[i]);
return 0;
}





Don't just read, write it, run it.....color>

RESULT:color>





This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

Bubble Sorting in C Language

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×