fork download
  1. #include <stdio.h>
  2.  
  3. #define SIZE 11
  4.  
  5. int main() {
  6. int data[SIZE] = {1, 2, 4, 6, 8, 9, 12, 15, 149, 156};
  7. int num, i, j, pos;
  8.  
  9. printf("整数を入力してください: ");
  10. scanf("%d", &num);
  11.  
  12. pos = SIZE - 1;
  13. for(i = 0; i < SIZE - 1; i++) {
  14. if(num < data[i]) {
  15. pos = i;
  16. break;
  17. }
  18. }
  19.  
  20. for(j = SIZE - 1; j > pos; j--) {
  21. data[j] = data[j - 1];
  22. }
  23.  
  24. data[pos] = num;
  25.  
  26. for(i = 0; i < SIZE; i++) {
  27. printf("%5d", data[i]);
  28. }
  29. printf("\n");
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 5316KB
stdin
117
stdout
整数を入力してください:     1    2    4    6    8    9   12   15  117  149  156