Arithmetic

C语言-结构体及其使用

PineappleCat · 5月21日 · 2019年 713次已读

Description

某小组5人,每人三项数据:姓名、年龄、分数,键盘输入这些人的数据,求小组的平均分及成绩最高者的数据

说明:年龄和分数都是整数

Input

键盘输入5个人的数据

Output

输出平均分及成绩最高者的数据

注:后台数据可以保证平均分是一个整数,没有小数

Sample Input

aaa 18 90 bbb 19 80 ccc 19 80 ddd 18 60 eee 18 70

Sample Output

76

aaa,18,90

#include <stdio.h>
#include <stdlib.h>
struct student{
    char name[10];
    int age;
    int grade;
}a[5];
int main()
{
    int i,sum=0,max=0;
    for(i=0;i<5;i++){
        scanf("%s %d %d",a[i].name,&a[i].age,&a[i].grade);
        sum+=a[i].grade;
        if(a[i].grade>a[max].grade){
            max = i;
        }
    }
   printf("%d\n%s,%d,%d",sum/5,a[max].name,a[max].age,a[max].grade);
   return 0;
}

Click here to view the copyright notice of this site(点击此处查看本站版权声明)
0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!