4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者

简介: 4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者

4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者

#include <stdio.h>//已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者
struct stu{
    char sno[10];
    char name[10];
    int score;
}student[5]={
        {"101","sss",45},
        {"102", "Zhang ping", 62.5},
        {"103", "He fang",     92.5},
        {"104", "Cheng ling",  87},
        {"105", "Wang ming",58},
};
int main() {
    struct stu p;
    int max=0;
    for (int i = 0; i <5; ++i) {
        if(student[i].score>max){
            max=student[i].score;
            p=student[i];
        }
        printf("%s %s %d",student[i].sno,student[i].name,student[i].score);
        printf("\n");
    }
    printf("the highest is %s %s %d",p.sno,p.name,p.score);    return 0;
}

21.1.png


编写output()函数输入,输出5个学生的成绩记录,每个记录包括学号,姓名性别,年龄5门口成绩

#include <stdio.h>//
struct stu{
    char sno[10];
    char name[10];
    char sex[10];
    int age;
    int score[5];
}student[5]={
//        {"101","sss","man",45,{90,90,21,34,56}},
//        {"102","gg","woman",45,{90,80,51,94,66}},
};//
void outupt(struct stu student[],int n) {
    for (int i = 0; i < n; ++i) {
        printf("%s %s %s ", student[i].sno, student[i].name, student[i].sex);
        for (int j = 0; j <n ; ++j) {
            printf("%d ",student[i].score[j]);
        }
        printf("\n");
    }
}
int main() {
    struct stu p;
    int n= sizeof(student)/ sizeof(student[0]);
    printf("n=%d",n);
    for (int i = 0; i <n; ++i) {
        printf("input sno name sex age:\n");
        scanf("%s %s %s %d",student[i].sno, student[i].name, student[i].sex,&student[i].age);
        printf("input score:\n");
        for (int j = 0; j <5; ++j) {
            scanf("%d", &student[i].score[j]);
        }
        printf("\n");
    }
    outupt(student,n);
      return 0;
}

21.2.png


有10个学生,每个学生学习三门功课,计算每个人的平均成绩和总的不及格人数


#include <stdio.h>//有10个学生,每个学生学习三门功课,计算每个人的平均成绩和总的不及格人数
struct stu{
    char sno[10];
    int score[3];
}student[5]={
        {"107",{13,90,21}},
        {"105",{20,90,21}},
        {"103",{50,90,21}},
        {"104",{10,90,21}},
        {"102",{100,100,100}},
};//
int main() {
    int nopass=0;//定义不及格人数
    double sum=0;
    double ave=0.0;
    for (int i = 0; i < 5; ++i) {
            if(student[i].score[0]<60||student[i].score[1]<60||student[i].score[2]<60){
                nopass++;
            }
             sum=0;
            ave=0.0;
        for (int j = 0; j <3; ++j) {
            sum=student[i].score[j]+sum;
            printf("sum=%.2f  ",sum);
        }
        ave=sum/3.0;
        printf("%s aver is %.1f\n",student[i].sno,ave);
    }
    printf("no pass people is %d",nopass);
      return 0;
}


21.3.png

相关文章
|
3月前
学生成绩
【2月更文挑战第6天】学生成绩。
32 1
|
3月前
有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,并存到磁盘中
有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,并存到磁盘中
|
15天前
|
SQL 数据库连接 数据库
查询学号为10002学生的所有成绩
【8月更文挑战第5天】查询学号为10002学生的所有成绩。
29 5
|
15天前
|
SQL 固态存储 数据库连接
学号为10005的学生
【8月更文挑战第5天】学号为10005的学生。
27 2
|
1月前
五个学生成绩
【7月更文挑战第9天】五个学生成绩。
30 13
|
1月前
7-1 学生成绩排序
7-1 学生成绩排序
12 0
|
11月前
指针-成绩统计
指针-成绩统计
|
3月前
|
弹性计算 运维 Shell
文件年龄分析
【4月更文挑战第30天】
26 0
|
C++
成绩统计
小蓝给学生们组织了一场考试,卷面总分为100分,每个学生的得分都是一个0到100的整数。如果得分至少是60分,则称为及格。
75 0