阿伦


私信TA

用户名:874501825

访问量:17278

签 名:

等  级
排  名 1116
经  验 3096
参赛次数 3
文章发表 7
年  龄 0
在职情况 学生
学  校 汕头大学
专  业

  自我简介:

TA的其他文章

解题思路:
在上一个题目的基础上,运用结构体将学生的信息定义出来;

然后,在用一个处理函数将学生的信息输入进行处理;
注意事项:
学生信息的处理时,注意结构体中的定义,例如: struct student stu[100];

(这个代码其他的地方都比较通俗易懂)

参考代码:

typedef struct student{
  char id[100];
  char name[100];
  int score[3],allscore;
}stu[100];
void input(int n)
{
    struct student stu[100];
    int i,t=0;
    for(i=0;i<n;i++)
    {
        scanf("%s %s %d %d %d",stu[i].id,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
        stu[i].allscore=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
    }
    int max;
    int a1=stu[0].score[0],a2=stu[0].score[1],a3=stu[0].score[2];
    max=stu[0].allscore;
    for(i=1;i<n;i++)
    {
        if(max<stu[i].allscore)
        {
            max=stu[i].allscore;
            t=i;
        }
        a1=a1+stu[i].score[0];//求所有同学这门课的总分;
        a2=a2+stu[i].score[1];
        a3=a3+stu[i].score[2];
    }
    printf("%d %d %d\n",a1/n,a2/n,a3/n);
    printf("%s %s %d %d %d",stu[t].id,stu[t].name,stu[t].score[0],stu[t].score[1],stu[t].score[2]);
}
int main()
{
    int n;
    scanf("%d",&n);
    input(n);
    return 0;
}

如果大家有问题,欢迎留言一起讨论,学习!

 

0.0分

12 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

#include <stdio.h>
#include <stdlib.h>
struct Student{
    char num[100];
    char name[100];
    float grade1;
    float grade2;
    float grade3;
    }student[100];
//struct DATA data;
int main(){
    int num;
    scanf("%d",&num);
    getchar();
    int i;
    for(i=0;i<num;i++){
        scanf("%s%s%f%f%f",student[i].num,student[i].name,&student[i].grade1,&student[i].grade2,&student[i].grade3);
        getchar();
    }
    float a,b,c,sum;
    int flag=0;
    sum=(student[0].grade1+student[0].grade2+student[0].grade3);
    for(i=0;i<num;i++){
        a+=student[i].grade1;
        b+=student
2020-01-14 14:55:43
  • «
  • 1
  • »