fork download
  1. #include <stdio.h>
  2. #define N 40
  3. void FindMax(int score[], long num[], int n, int pMaxScore, long pMaxNum);
  4. int main(void)
  5. {
  6. int score[N], maxScore;
  7. int n, i;
  8. long num[N], maxNum;
  9. printf("How many students?");
  10. scanf("%d", &n); /* 从键盘输入学生人数n */
  11. printf("Input student's ID and score:\n");
  12. for (i=0; i<n; i++)
  13. {
  14. scanf("%ld%d", &num[i], &score[i]); /* 字母d前为字母l */
  15. }
  16. FindMax(score, num, n, maxScore, maxNum); /* 按值调用函数 */
  17. printf("maxScore = %d, maxNum = %ld\n", maxScore, maxNum);
  18. return 0;
  19. }
  20. /* 函数功能:计算最高分及其相应学生的学号 */
  21. void FindMax(int score[], long num[], int n, int pMaxScore, long pMaxNum)
  22. {
  23. int i;
  24. pMaxScore = score[0]; /* 假设score[0]为当前最高分 */
  25. pMaxNum = num[0]; /* 记录当前最高分学生的学号num[0] */
  26. for (i=1; i<n; i++) /* 对所有score[i]进行比较 */
  27. {
  28. if (score[i] > pMaxScore)/* 如果score[i]高于当前最高分 */
  29. {
  30. pMaxScore = score[i]; /* 用score[i]修改当前最高分 */
  31. pMaxNum = num[i]; /* 记录当前最高分学生的学号num[i] */
  32. }
  33. }
  34. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
How many students?Input student's ID and score:
maxScore = 0, maxNum = 0