从键盘输入某班学生某门课的成绩和学号(最多不超过40人),当输入为负值时,表示输入结束,用函数编程通过返回数组中最大元素的下标,查找并输出成绩的最高分及其所在的学生学号

从键盘输入某班学生某门课的成绩和学号(最多不超过40人),当输入为负值时,表示输入结束,用函数编程通过返回数组中最大元素的下标,查找并输出成绩的最高分及其所在的学生学号。

**输入格式要求:"%ld%d"  提示信息:"Input student’s ID and score:"  "input error!\n"

**输出格式要求:"Total students are %d\n"  "The highest is:%ld, %d\n"

程序运行示例如下:

Input student’s ID and score:070310122 84

Input student’s ID and score:070310123 83

Input student’s ID and score:070310124 88

Input student’s ID and score:070310125 87

Input student’s ID and score:070310126 61

Input student’s ID and score:-1 -1

Total students are 5

The highest is:70310124, 88

#include <stdio.h>
#include <stdlib.h>
int main()
{
    long ID[41];
    int score[41];
    int j=0;
    do{
        printf("Input student’s ID and score:");
        scanf("%ld%d",&ID[j],&score[j]);
        j++;
    }while(ID[j-1]>0||score[j-1]>0);
    printf("Total students are %d\n",j-1);
    int t,i,k,a;
    for(i=0;i<j;i++)
    {
        for(k=1;k<j;k++)
        {
            if(score[k]>score[k-1])
            {
                t=score[k-1];
                score[k-1]=score[k];
                score[k]=t;
                a=ID[k-1];
                ID[k-1]=ID[k];
                ID[k]=a;
            }
        }
    }
    printf("The highest is:%ld, %d\n",ID[0],score[0]);
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值