fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define N 50
  6.  
  7. int main(void)
  8. {
  9. int data[N];
  10. int i, j, key;
  11.  
  12. srand((unsigned int)time(NULL));
  13.  
  14. for(i = 0; i < N; i++)
  15. data[i] = rand() % 1000;
  16.  
  17. /* 挿入ソート */
  18. for(i = 1; i < N; i++)
  19. {
  20. key = data[i];
  21. j = i - 1;
  22.  
  23. while(j >= 0 && data[j] > key)
  24. {
  25. data[j + 1] = data[j];
  26. j--;
  27. }
  28.  
  29. data[j + 1] = key;
  30. }
  31.  
  32. printf("並べ替え後\n");
  33.  
  34. for(i = 0; i < N; i++)
  35. printf("%d ", data[i]);
  36.  
  37. printf("\n\n");
  38.  
  39. printf("先頭2桁が10の数\n");
  40.  
  41. for(i = 0; i < N; i++)
  42. {
  43. if(data[i] >= 100 && data[i] <= 109)
  44. printf("%d ", data[i]);
  45. }
  46.  
  47. printf("\n");
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
並べ替え後
13 80 103 148 149 171 184 193 233 239 240 305 307 310 341 349 376 400 407 437 442 444 465 477 492 504 523 530 550 570 576 599 625 668 693 695 735 750 775 786 815 838 861 878 901 908 936 941 971 982 

先頭2桁が10の数
103