SHARE
TWEET

Untitled

a guest Nov 16th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.   int n, array[1000], c, d, t, flag = 0;
  6.  
  7.   printf("Enter number of elements\n");
  8.   scanf("%d", &n);
  9.  
  10.   printf("Enter %d integers\n", n);
  11.  
  12.   for (c = 0; c < n; c++)
  13.     scanf("%d", &array[c]);
  14.  
  15.   for (c = 1 ; c <= n - 1; c++) {
  16.     t = array[c];
  17.  
  18.     for (d = c - 1 ; d >= 0; d--) {
  19.       if (array[d] > t) {
  20.         array[d+1] = array[d];
  21.         flag = 1;
  22.       }
  23.       else
  24.         break;
  25.     }
  26.     if (flag)
  27.       array[d+1] = t;
  28.   }
  29.  
  30.   printf("Sorted list in ascending order:\n");
  31.  
  32.   for (c = 0; c <= n - 1; c++) {
  33.     printf("%d\n", array[c]);
  34.   }
  35.  
  36.   return 0;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top