fork(1) download
  1. // kadai8-1.c
  2. #include <stdio.h>
  3. #include <malloc.h> //malloc()を使うため
  4. #include <stdlib.h> //exit(1)を使うため
  5.  
  6. struct each_score {
  7. int ten; //点数
  8. int gou; //合格・不合格
  9. };
  10.  
  11. struct SEISEKI {
  12. char name[50];
  13. struct each_score kokugo;
  14. struct each_score sugaku;
  15. };
  16.  
  17. void check_score(int borderline, struct SEISEKI *a)
  18. {
  19. a->kokugo.gou = (a->kokugo.ten < borderline) ? 0 : 1;
  20. a->sugaku.gou = (a->sugaku.ten < borderline) ? 0 : 1;
  21. }
  22.  
  23. void print_score(struct SEISEKI a)
  24. {
  25. char *gou[] = {"rejection","accept"};
  26.  
  27. printf("name: %s\n", a.name);
  28. printf("kokugo %d : %s\n", a.kokugo.ten, gou[a.kokugo.gou]);
  29. printf("sugaku %d : %s\n", a.sugaku.ten, gou[a.sugaku.gou]);
  30. }
  31.  
  32. int main()
  33. {
  34. struct SEISEKI *score;
  35. int num;
  36. int i;
  37.  
  38. printf("Input number of students >\n");
  39. scanf("%d", &num);
  40. score = (struct SEISEKI *)malloc(sizeof(struct SEISEKI) * num);
  41. if (score == NULL) {//メモリ割付に失敗した場合
  42. printf("Memory overflow\n");
  43. exit(1);//異常があったことをOSに伝えて終了する。
  44. }
  45. for (i = 0; i < 3; i++) {
  46. scanf("%49s%d%d", score[i].name, &score[i].kokugo.ten, &score[i].sugaku.ten);
  47. check_score(60, &score[i]);
  48. }
  49. for (i = 0; i < 3; i++) {
  50. print_score(score[i]);
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.02s 2860KB
stdin
3
yamauchi 60 70
yamada 30 90
tougou 70 80
stdout
Input number of students >
name: yamauchi
kokugo 60 : accept
sugaku 70 : accept
name: yamada
kokugo 30 : rejection
sugaku 90 : accept
name: tougou
kokugo 70 : accept
sugaku 80 : accept