Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. /* Program written by Mst. Sima Khatun */
  2. //bubble sort
  3.  
  4. #include<stdio.h>
  5.  
  6. int main()
  7. {
  8.     int n,i,j,temp;
  9.  
  10.     printf("Enter how many number you want to assign to the array \n");
  11.     scanf("%d",&n);
  12.     int num[n];
  13.     printf("enter %d number to the array \n",n);
  14.     for(i=0;i<n;i++)
  15.     {
  16.         scanf("%d",&num[i]);
  17.     }
  18.  
  19.  
  20.     for(i=0;i<n;i++)
  21.     {
  22.         for(j=0;j<n-i;j++)
  23.         {
  24.             if(num[j]>num[j+1])
  25.             {
  26.                 temp = num[j];
  27.                 num[j] = num[j+1];
  28.                 num[j+1] = temp;
  29.             }
  30.         //    printf("%d\n",num[j]);
  31.         }
  32.       //  printf("\n\n");
  33.  
  34.     }
  35.  
  36.     //printf("\n\n\n*********************************\n\n");
  37.  
  38.  
  39.     for(i=0;i<n;i++)
  40.     {
  41.         printf("%d ",num[i]);
  42.     }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement