fork download
  1. #include<stdio.h>
  2. #define NUM 5
  3.  
  4. typedef struct Student
  5. {
  6. int no; /*番号*/
  7. char name[10]; /*氏名*/
  8. int score; /*得点*/
  9. }Student;
  10.  
  11. /*int search(student date[],int no);*/
  12.  
  13. int main(void)
  14. {
  15. Student student[NUM] =
  16. {
  17. { 1,"taro.s",100 },
  18. { 2,"jiro.y",80 },
  19. { 4,"saburo.h",65 },
  20. { 5,"shiro.k",20 },
  21. { 8,"goro.s",93 },
  22. };
  23.  
  24. int i;
  25. int ban;
  26.  
  27. printf("───────────────────────────────────\n");
  28. printf("番号│ 氏名 │ 得点\n");
  29. printf("───────────────────────────────────\n");
  30. for (i = 0; i < NUM; i++)
  31. {
  32. printf("%4d│%10s│%5d\n", student[i].no, student[i].name, student[i].score);
  33. }
  34. printf("───────────────────────────────────\n");
  35.  
  36. printf("検索する番号を入力してください:");
  37. scanf("%d", &ban);
  38.  
  39. if (0 <= ban&&NUM > ban)
  40. {
  41. printf("番号:%d\n", student[ban].no);
  42. printf("氏名:%s\n", student[ban].name);
  43. printf("得点:%d\n", student[ban].score);
  44.  
  45. return 0;
  46. }
  47. else
  48. {
  49. return -1;
  50. }
  51. }
  52.  
Success #stdin #stdout 0s 2160KB
stdin
1
stdout
───────────────────────────────────
番号│ 氏名 │ 得点
───────────────────────────────────
   1│    taro.s│  100
   2│    jiro.y│   80
   4│  saburo.h│   65
   5│   shiro.k│   20
   8│    goro.s│   93
───────────────────────────────────
検索する番号を入力してください:番号:2
氏名:jiro.y
得点:80