Praveen | Typing Speed Test is a very useful Software available for free Download.

C Programs to Bubble sort

      Bubble sorting to sort numbers, And arrange them in ascending order or descending order. Bubble sorting means one number to check next number then exchange or not, Then again check to second number to check third number then exchange or not By this conditions, This process is perform sequentially.


Bubble sorting in Ascending order C programming code

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

void main()
{
   int a[100], n, i, j, temp;
   clrscr();
   printf("\n Enter number of elements ");
   scanf("%d", &n);
   printf("\n Enter %d integer numbers ", n);
   for ( i = 0 ; i < n ; i++ )
      scanf("%d", &a[i]);
   for ( i = 0 ; i < ( n - 1 ) ; i++ )
   {
      for ( j = 0 ; j < ( n - i - 1 ) ; j++ )
      {
          if ( a[j] > a[j+1] )
          {
             temp = a[j];
             a[j] = a[j+1];
             a[j+1] = temp;
          }
      }
   }
   printf("\n Sorted list in ascending order:-");
   for ( i = 0 ; i < n ; i++ )
       printf(" %d,", a[i]);

   getch();
}


 Output:-
                    






No comments:

Post a Comment