C program to perform Bubble Sorting.

This c program show the bubble sorting algorithm of data structure, perform in c programming to sorting array elements. Here the logic is first element is check with 2nd element if it is lower than first it will swap with them other vise it check 3rd element and so on. Than after 2nd is check with 3rd. If it is lower it swap other wise it check 4th element and so on. This algorithm of sorting is also called Bubble sort algorithm.



C program for Bubble Sort


#include<stdio.h>

void main()
{
       int i,j,n,temp;
       int A[50];
       clrscr();
       printf("Enter the no. of element::");
       scanf("%d",&n);

       printf("Enter elements in array\n");

       for(i=0;i<n;i++)
       {
              printf("element %d is : ",i+1);
              scanf("%d",&A[i]);
       }

       printf("\nElements enter by you is::\n");
       for(i=0;i<n;i++)
       {
              printf("%d\t",A[i]);
       }

       for(i=0;i<n;i++)
       {
              for(j=i+1;j<n;j++)
              {
                     if(A[i]>A[j])
                     {
                            temp=A[i];
                            A[i]=A[j];
                            A[j]=temp;
                     }
              }
       }
             
       printf("\nelements sorted in asending order\n");
       for(i=0;i<n;i++)
       {
              printf("%d\t",A[i]);
       }

       getch();

}



c program to perform sorting - bubble sort

1 comments: