勇敢的杰


私信TA

用户名:153144

访问量:12419

签 名:

等  级
排  名 1244
经  验 2956
参赛次数 1
文章发表 21
年  龄 0
在职情况 学生
学  校 武昌工学院
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include<stdio.h>

struct Student

{

char name[20];//名字

double grade_first;//第一科成绩

double grade_second;//第二科成绩

double grade_third;//第三科成绩

};


int main()

{

struct Student student[100];//声明

int num=0;//人数

int i;

char arr[100];//学号,如果写在结构体里面,就无法弄出字符了。

double first_sum=0;//第一学科总分数,兼平均分(最后算出)

double two_sum=0;//第二学科总分数,兼平均分(最后算出)

double three_sum=0;//第三学科总分数,兼平均分(最后算出)

double average[100];//每个学生的总分记录

double maxvalue=0;

int flag=0;

scanf("%d",&num);

getchar();

for(i=0;i<num;i++)

{

scanf("%c %s %lf %lf %lf",&arr[i],student[i].name,&student[i].grade_first,&student[i].grade_second,&student[i].grade_third);//输入数据

getchar();

}

for(i=0;i<num;i++)

{

first_sum=first_sum+student[i].grade_first;//算第一科总分

two_sum=two_sum+student[i].grade_second;//算第二科总分

three_sum=three_sum+student[i].grade_third;//算第三科总分

average[i]=student[i].grade_first+student[i].grade_second+student[i].grade_third;//记录每个人三科成绩总分

if(i==num-1)

{

first_sum=(double)(first_sum/num);//第一科算平均,

two_sum =(double)(two_sum/num);//第二科算平均

three_sum=(double)(three_sum/num);//第三科算平均

}

}

for(i=0;i<num;i++)

{

if(average[i]>=maxvalue)

{

maxvalue=average[i];//获得成绩最高的学生

flag=i;

}

}

printf("%.0f %.0f %.0f\n", first_sum,two_sum,three_sum);//输出平均值

printf("%c %s %.0lf %.0lf %.0lf\n",arr[flag],student[flag].name,student[flag].grade_first,student[flag].grade_second,student[flag].grade_third);

return 0;

}


 

0.0分

0 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区