例2.2 有50个学生,要求输出成绩在80分以上的学生的学号和成绩。

曾经终败给现在 2021-11-11 12:24 479阅读 0赞

C语言程序设计(第四版) 谭浩强 个人设计

例2.2 有50个学生,要求输出成绩在80分以上的学生的学号和成绩。

代码块:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void student_info(int n[], double s[], int nu); // Define the function of the input.
  4. void score_above80(int n[], double s[], int nu); // Define the function which the score is above 80.
  5. int main()
  6. {
  7. int num[50], count;
  8. double score[50];
  9. printf("Enter the number of student: "); // Free to enter the total numbers of the students.
  10. scanf("%d", &count);
  11. student_info(num, score, count);
  12. score_above80(num, score, count);
  13. system("pause");
  14. return 0;
  15. }
  16. void student_info(int n[], double s[], int nu)
  17. {
  18. int i;
  19. for(i=0; i<nu; i++){
  20. printf("Enter No.%d student number: ", i+1);
  21. scanf("%d", &n[i]);
  22. printf("Enter No.%d student score: ", i+1);
  23. scanf("%lf", &s[i]);
  24. /* The following 3 lines is exclude unreasonable scores. */
  25. while(s[i]<0||s[i]>100){
  26. printf("Score Error! Retry!\nEnter No.%d student score: ", i+1);
  27. scanf("%lf", &s[i]);
  28. }
  29. }
  30. }
  31. void score_above80(int n[], double s[], int nu)
  32. {
  33. int i;
  34. for(i=0; i<nu; i++)
  35. if (s[i]>80)
  36. printf("%d %lf\n", n[i], s[i]);
  37. }

发表评论

表情:
评论列表 (有 0 条评论,479人围观)

还没有评论,来说两句吧...

相关阅读