Problem C. S08-05 学生成绩与学号

8.5,请参考课本例8.7程序中的函数ReadScore()和FindMax(), 从健盘输入某班学生某门课的成绩和学号(最多不超过40人),当输入为负值时,表示输入结束,用函数编程通过返回数组中最大元素的下标,查找并输出成绩的最高分及其对应的学生学号。

输入

学号和成绩,直到有负数的出现

输出

有效人数,最高分人的分数和学号

样例

标准输入复制文本
1001 98
1002 99
1003 92
1001 -1
标准输出复制文本
Total students are 3
The highest is 1002, score is 99
标准输入复制文本
202001 56
202002 98
-1 100
标准输出复制文本
Total students are 2
The highest is 202002, score is 98
标准输入复制文本
2020023861 500
2020023877 20
-1 -1
标准输出复制文本
Total students are 2
The highest is 2020023861, score is 500

难点:

找最大值

 for(int i=1;i<=n;i++)
    {
        if (score[i]>score[max])
        {
            max=i;
        }


#include <stdio.h>
int Read(long number[],int score[]){
    int i=-1;
    do{
        i++;
        scanf("%ld",&number[i]);
        scanf("%d",&score[i]);
    }while (number[i]>=0&&score[i]>=0);
    return i;
}
int FindMax (int score[],int n){int max=0;
    for(int i=1;i<=n;i++)
    {
        if (score[i]>score[max])
        {
            max=i;
        }
    }
    return max;
}
int main ()
{
    int score[40],maxnum,n;
    long  number[40];
    n=Read(number,score);
    maxnum=FindMax(score,n);
    printf("Total students are %d\n",n);
    printf("The highest is %ld, score is %d",number[maxnum],score[maxnum]);
    return 0;
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值