Advertisement
Waliullah8328

Bubble Sorting Accending and Decending

Jun 10th, 2021
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int arr[10],n,i,j,temp;
  5.     printf("Enter how many Element you want to insert : \n");
  6.     scanf("%d",&n);
  7.     printf("Enter your Element  : \n");
  8.     for(i=0; i<n; i++)
  9.     {
  10.         scanf("%d",&arr[i]);
  11.     }
  12.     // Bubble sorting Start
  13.     for(i=0; i<n-1; i++)
  14.     {
  15.  
  16.         for(j=0; j<n-1; j++)
  17.         {
  18.  
  19.             if(arr[j]>arr[j+1])
  20.             {
  21.  
  22.                 temp=arr[j];
  23.                 arr[j]=arr[j+1];
  24.                 arr[j+1]= temp;
  25.             }
  26.         }
  27.     }
  28.     //Bubble Sorting End
  29.     printf("Accending Order : \n");
  30.  
  31.     for(i=0; i<n; i++)
  32.     {
  33.         printf("%d\n",arr[i]);
  34.     }
  35.       for(i=0; i<n-1; i++)
  36.     {
  37.  
  38.         for(j=0; j<n-1; j++)
  39.         {
  40.  
  41.             if(arr[j+1]>arr[j])
  42.             {
  43.  
  44.                 temp=arr[j+1];
  45.                 arr[j+1]=arr[j];
  46.                 arr[j]= temp;
  47.             }
  48.         }
  49.     }
  50.       printf("Decending Order : \n");
  51.  
  52.     for(i=0; i<n; i++)
  53.     {
  54.         printf("%d\n",arr[i]);
  55.     }
  56.     return 0;
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement