fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n, x, a[100], i, pos;
  5.  
  6. scanf("%d", &n);
  7. for (i = 0; i < n; i++) scanf("%d", &a[i]);
  8. scanf("%d", &x);
  9.  
  10.  
  11. for (pos = 0; pos < n && a[pos] < x; pos++);
  12.  
  13.  
  14. for (i = n; i > pos; i--) a[i] = a[i - 1];
  15. a[pos] = x;
  16. n++;
  17.  
  18. for (i = 0; i < n; i++) printf("%d ", a[i]);
  19. printf("\n");
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5320KB
stdin
10
1 2 4 6 8 9 12 15 149 156
5
stdout
1 2 4 5 6 8 9 12 15 149 156