Monday, 10 September 2018

Program for sorting of array element using bubble sort in C

What is sorting ?

The term sorting means arrangement of element in particular order i.e in ascending or descending  order is known as sorting.

Example:: 45,55,25,35,65
Sorted data :: 25,35,45,55,65

How bubble sort work ?

Bubble sort method works on method of comparing two consecutive digits.

45,55,25,35,65

working::
45,55,25,35,65
45,25,55,35,65
25,45,55,35,65
25,45,35,55,65
25,35,45,55,65   ( sorted data )

Program for bubble sort in c 

#include<stdio.h>
#include<conio.h>
void main ()
{
int i,j,n,t,a[100];
clrscr ();
printf ("\n Enter size of array:");
scanf ("%d", &n);
printf ("\n Enter element in array:");
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
}
for (i=o;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf (sorted array=");
for (i=0;i<n;i++)
{
printf ("\t %d",a[i]);
}
getch ();
}



15 comments:

  1. I am sure this is very useful because I have learnt alot just from reading this sorting.

    ReplyDelete
  2. Hmmm. Interesting but I really dont understand it!

    ReplyDelete
  3. I am sure this will be helpful for a programmer.

    ReplyDelete
  4. No idea programming was this interesting. Thanks

    ReplyDelete
  5. I took a programming course in college, it is very complicated.

    ReplyDelete
  6. TBH hurts my brain!! Hahah props to you!

    ReplyDelete
  7. Thanks to your posts, I am starting to get motivated to learn coding. :)

    ReplyDelete
  8. This is really helps to all of beginner programmers! Nice one.

    ReplyDelete
  9. Goodness, this is too techy for me

    ReplyDelete
  10. Oh wow, all but greek to me. But really interested in coding. Thanks a lot for such an informative post.

    ReplyDelete
  11. English please....this makes me want to learn coding.....

    ReplyDelete
  12. Wow this is another level of programming language. Very interesting!

    ReplyDelete
  13. I don’t understand this at all. Maybe next time explain it in layman’s terms

    ReplyDelete
  14. I don't understand this really ut I know it would be helpful to someone someday.

    ReplyDelete
  15. I just stared at this for so long trying to understand lol But i'm sure it's helpful for others.

    ReplyDelete

Featured post

Program to find maximum of three number using user define function in C++

A function can be define by the user as per the requirement of the user or programmer . To implement a user define function , a programmer ...