栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

从键盘输入某班学生的学号和某门课的成绩(每班人数最多不超过40人),当输入为负值时,表示输入结束,试编程从键盘任意输入一个学号,查找该学号学生的成绩。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从键盘输入某班学生的学号和某门课的成绩(每班人数最多不超过40人),当输入为负值时,表示输入结束,试编程从键盘任意输入一个学号,查找该学号学生的成绩。

**提示信息:"Input student’s ID and score:"
**输入格式: "%ld%d" 
**提示信息: "Input the searching ID:" 
**输入格式要求:"%ld" 
**输出格式要求:"Total students are %dn"
                            "score = %dn"         "Not found!n"
程序的两次运行示例如下:
① Input student’s ID and score:1910122 84
Input student’s ID and score:1910123 83
Input student’s ID and score:1910124 88
Input student’s ID and score:1910125 87
Input student’s ID and score:1910126 61
Input student’s ID and score:-1 -1
Total students are 5
Input the searching ID:1910123
score =  83
②  Input student’s ID and score:1910122 84
Input student’s ID and score:1910123 83
Input student’s ID and score:1910124 88
Input student’s ID and score:1910125 87
Input student’s ID and score:1910126 61
Input student’s ID and score:-1 -1
Total students are 5
Input the searching ID:1910128
Not found!
#include
#include
int main()
{
    int id;
    long ID[40];
    int score[40];
    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 %dn", j-1);
    printf("Input the searching ID:");
    scanf("%ld", &id);
    for(int i = 0; i < j-1; i++)
    {
        if(ID[i] == id)
        {
            printf("score = %dn", score[i]);
            exit(0);
        }
    }
    printf("Not found!n");
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/675742.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号