Showing posts with label bubble sort in c. Show all posts
Showing posts with label bubble sort in c. Show all posts

Tuesday, 27 February 2018

program of Bubble Sort


Program

 #include<stdio.h>
 #include<conio.h>
 #define max 5

 void main()
 {
   int arry[max];
   int i,j,temp;
   printf("enter elements :");
   for(int p=0;p<=max-1;p++)
   {
     scanf("%d",&arry[p]);
   }


   for(i=1;i<=max-1;i++)
   {
     for(j=0;j<=max-1-i;j++)
      {
       if(arry[j] > arry[j+1])
         {
    temp=arry[j];
    arry[j]=arry[j+1];
    arry[j+1]=temp;
         }
       }
    }
        printf("after sorting: \n");
        for(int k=0;k<=max-1;k++)
        {
          printf("%d \n",arry[k]);
        }
    getch();
 }






Output

enter elements : 50
                          10
                          33
                          05
                          15

  after sorting:  05
                         10
                         15
                         33
                         50