标题:怎么用c写一个成绩单·
只看楼主
我是一个黑客
Rank: 1
等 级:新手上路
帖 子:69
专家分:2
注 册:2018-6-11
结帖率:81.82%
已结贴  问题点数:20 回复次数:1 
怎么用c写一个成绩单·
从键盘上输入N名学生的姓名和某科成绩,按分数从高到低打印出成绩单。对非法数据,要求重新输入

搜索更多相关主题的帖子: 成绩 输入 数据 要求 重新 
2019-06-10 11:19
吕孟伟
Rank: 8Rank: 8
等 级:贵宾
威 望:27
帖 子:200
专家分:870
注 册:2018-10-4
得分:20 
程序代码:
#include <stdio.h>
#include <stdlib.h>

struct Score_report {
    char name[7];
    float grade;
};
#define N 3
void Getsort(struct Score_report score[]);
int main(void)
{
    struct Score_report temp={0};
    struct Score_report score[N];

    int i, j;
    
    
    for(i=0; i<N; i++)
    {
        printf("Please enter the %d student's name and grade:\n", i+1);
        printf("Please you input the Name:");
        scanf("%s", &score[i].name);
        printf("Please you input the Grade:");
        scanf("%f", &score[i].grade);
        if(score[i].grade < 0.0 ||score[i].grade > 100.0)
        {
            printf("The grade you entered is not reasonable!\n");
            printf("Please you re-enter:");
            scanf("%f", &score[i].grade);
        }
    }
    
    
    for(i = 0; i < N-1; i++)
    {
        for(j = 0; j < N - 1 - i; j++)
        {
            if(score[j].grade < score[j+1].grade)
            {
                temp = score[j];
                score[j] = score[j+1];
                score[j+1] = temp;
            }
        }
    }
    printf("\n\n");
    printf("*************Score report***************\n");
    printf("\tName\tScore\n");
    for(i=0; i<N; i++)
    {
        printf("\t%s\t%.1f\n", score[i].name, score[i].grade);
    }
    system("pause");
    return 0;
}

代码输出:
Please enter the 1 student's name and grade:
Please you input the Name:聂小倩
Please you input the Grade:-9
The grade you entered is not reasonable!
Please you re-enter:78
Please enter the 2 student's name and grade:
Please you input the Name:宁采臣
Please you input the Grade:109
The grade you entered is not reasonable!
Please you re-enter:54
Please enter the 3 student's name and grade:
Please you input the Name:燕赤霞
Please you input the Grade:99


*************Score report***************
        Name    Score
        燕赤霞  99.0
        聂小倩  78.0
        宁采臣  54.0

[此贴子已经被作者于2019-6-10 15:47编辑过]


借用一下侯捷的话:勿在浮沙筑高台。
2019-06-10 15:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-495186-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.219755 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved