fork download
  1. // for_exp.c
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6. int score[100]={0};
  7. int student_num = 0;
  8.  
  9. printf("生徒の数を入力してください: ");
  10. scanf("%d", &student_num); // <= 6
  11. if(student_num <= 0)return -1; // student_numが0以下だったら、プログラムを終了
  12.  
  13. for (int i = 0;;) { // 普通はこんなことしません
  14. int input_score;
  15. printf("点数を入力してください: ");
  16. scanf("%d",&input_score); // <= 80 70 30 40 90 10
  17. if (!(0 <= input_score && input_score <= 100)) {
  18. printf("もう一度");
  19. continue;
  20. }
  21. score[i++] = input_score;
  22. if (i >= student_num)break;
  23. }
  24.  
  25. for(int i = 0; i < student_num; ++i) {
  26. printf("score[%d]: %d\n", i, score[i]);
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5436KB
stdin
6
80 70 30 40 90 10
stdout
生徒の数を入力してください: 点数を入力してください: 点数を入力してください: 点数を入力してください: 点数を入力してください: 点数を入力してください: 点数を入力してください: score[0]: 80
score[1]: 70
score[2]: 30
score[3]: 40
score[4]: 90
score[5]: 10