fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct student{
  4.  
  5. int english;
  6. int chinese;
  7. int math;
  8. int physics;
  9. char name[20];
  10. };
  11. void getHighestGrade(struct student*);
  12. void getNoPassGrade(struct student*);
  13. void getAvgGrade(struct student*);
  14. int main()
  15. {
  16. int loop;
  17.  
  18. struct student studentA[5];
  19. for(loop=0;loop<5;loop++){
  20. printf("請輸入學生名字:");
  21. scanf("%s",&studentA[loop].name);
  22. printf("請輸入英文成績:");
  23. scanf("%d",&studentA[loop].english);
  24. printf("請輸入國文成績:");
  25. scanf("%d",&studentA[loop].chinese);
  26. printf("請輸入數學成績:");
  27. scanf("%d",&studentA[loop].math);
  28. printf("請輸入物理成績:");
  29. scanf("%d",&studentA[loop].physics);
  30. }
  31. printf("------------ans1-----------\n");
  32. for(loop=0;loop<5;loop++){
  33. printf("%s\t英文:%d,中文:%d,數學:%d,物理:%d\n",studentA[loop].name,studentA[loop].english,studentA[loop].chinese,studentA[loop].math,studentA[loop].physics);
  34. }
  35. getHighestGrade(&studentA);
  36. getNoPassGrade(&studentA);
  37. getAvgGrade(&studentA);
  38. return 0;
  39. }
  40. void getHighestGrade(struct student*strStudent){
  41. int loop,loop1;
  42. int a=0;
  43. for(loop=0;loop<4;loop++){
  44. for(loop1=0;loop1<4-loop;loop1++){
  45. if(strStudent[loop1].english>strStudent[loop1+1].english){
  46. a=strStudent[loop1].english;
  47. strStudent[loop1].english=strStudent[loop1+1].english;
  48. strStudent[loop1+1].english=a;
  49. }
  50. }
  51. }
  52. for(loop=0;loop<4;loop++){
  53. for(loop1=0;loop1<4-loop;loop1++){
  54. if(strStudent[loop1].chinese>strStudent[loop1+1].chinese){
  55. a=strStudent[loop1].chinese;
  56. strStudent[loop1].chinese=strStudent[loop1+1].chinese;
  57. strStudent[loop1+1].chinese=a;
  58. }
  59. }
  60. }
  61. for(loop=0;loop<4;loop++){
  62. for(loop1=0;loop1<4-loop;loop1++){
  63. if(strStudent[loop1].math>strStudent[loop1+1].math){
  64. a=strStudent[loop1].math;
  65. strStudent[loop1].math=strStudent[loop1+1].math;
  66. strStudent[loop1+1].math=a;
  67. }
  68. }
  69. }
  70. for(loop=0;loop<4;loop++){
  71. for(loop1=0;loop1<4-loop;loop1++){
  72. if(strStudent[loop1].physics>strStudent[loop1+1].physics){
  73. a=strStudent[loop1].physics;
  74. strStudent[loop1].physics=strStudent[loop1+1].physics;
  75. strStudent[loop1+1].physics=a;
  76. }
  77. }
  78. }
  79. printf("英文最高分=%d\n",strStudent[4].english);
  80. printf("中文最高分=%d\n",strStudent[4].chinese);
  81. printf("數學最高分=%d\n",strStudent[4].math);
  82. printf("物理最高分=%d\n",strStudent[4].physics);
  83. }
  84. void getNoPassGrade(struct student*strStudent){
  85. int loop;
  86. printf("英文不及格:");
  87. for(loop=0;loop<5;loop++){
  88. if(strStudent[loop].english<60){
  89. printf("%s",strStudent[loop].name);
  90. }
  91. }
  92. printf("\n");
  93. printf("國文不及格:");
  94. for(loop=0;loop<5;loop++){
  95. if(strStudent[loop].chinese<60){
  96. printf("%s",strStudent[loop].name);
  97. }
  98.  
  99. }
  100. printf("\n");
  101. printf("數學不及格:");
  102. for(loop=0;loop<5;loop++){
  103. if(strStudent[loop].math<60){
  104. printf("%s",strStudent[loop].name);
  105. }
  106.  
  107. }
  108. printf("\n");
  109. printf("物理不及格:");
  110. for(loop=0;loop<5;loop++){
  111. if(strStudent[loop].physics<60){
  112. printf("%s",strStudent[loop].name);
  113. }
  114. }
  115. printf("\n");
  116. }
  117. void getAvgGrade(struct student*strStudent){
  118. float avgenglish=0;
  119. float avgchinese=0;
  120. float avgmath=0;
  121. float avgphysics=0;
  122. int loop;
  123. for(loop=0;loop<5;loop++){
  124. avgenglish += strStudent[loop].english;
  125. avgchinese += strStudent[loop].chinese;
  126. avgmath += strStudent[loop].math;
  127. avgphysics += strStudent[loop].physics;
  128. }
  129. printf("英文平均成績:%.2f\n",avgenglish/5);
  130. printf("國文平均成績:%.2f\n",avgchinese/5);
  131. printf("數學平均成績:%.2f\n",avgmath/5);
  132. printf("物理平均成績:%.2f\n",avgphysics/5);
  133.  
  134.  
  135. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
請輸入學生名字:請輸入英文成績:請輸入國文成績:請輸入數學成績:請輸入物理成績:請輸入學生名字:請輸入英文成績:請輸入國文成績:請輸入數學成績:請輸入物理成績:請輸入學生名字:請輸入英文成績:請輸入國文成績:請輸入數學成績:請輸入物理成績:請輸入學生名字:請輸入英文成績:請輸入國文成績:請輸入數學成績:請輸入物理成績:請輸入學生名字:請輸入英文成績:請輸入國文成績:請輸入數學成績:請輸入物理成績:------------ans1-----------
�!�D�	英文:11538501,中文:0,數學:151623527,物理:11095
W+	英文:11095,中文:4096,數學:0,物理:150682528
4 �W+	英文:151708329,中文:11095,數學:-1,物理:0
	英文:0,中文:2097152,數學:0,物理:15775487
	英文:1154606558,中文:32767,數學:151330277,物理:11095
英文最高分=1154606558
中文最高分=2097152
數學最高分=151623527
物理最高分=150682528
英文不及格:�!�D�
國文不及格:�!�D�
數學不及格:�!�D�W+4 �W+
物理不及格:�!�D�
英文平均成績:263572912.00
國文平均成績:429022.00
數學平均成績:60590760.00
物理平均成績:33296042.00