Ghislain_Mike

Q 54

Mar 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     int i, j, num, temp;
  5.  
  6.     printf("Enter the value of num \n");
  7.     scanf("%d", &num);
  8.  
  9.     int array[num];
  10.  
  11.     printf("\nEnter the elements one by one (only use 0, 1, 2) \n");
  12.  
  13.     for (i = 0; i < num; i++) {
  14.         scanf("%d", &array[i]);
  15.     }
  16.  
  17.     printf("\nInput array is \n");
  18.     for (i = 0; i < num; i++) {
  19.         printf("%d\n", array[i]);
  20.     }
  21.  
  22.     for (i = 0; i < num; i++){
  23.         for (j = 0; j < (num - i - 1); j++){
  24.             if (array[j] > array[j + 1]){
  25.                 temp = array[j];
  26.                 array[j] = array[j + 1];
  27.                 array[j + 1] = temp;
  28.             }
  29.         }
  30.     }
  31.     printf("\nArray elements arranged in ascending order\n");
  32.     for (i = 0; i < num; i++)
  33.     {
  34.         printf("%d\n", array[i]);
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment