南邮编程在线编程题十六:求平均值和最大值

某学习小组有3个人,每个人的信息包括:学号、姓名和成绩。要求从键盘上输入他们的信息,并求出平均成绩以及最高成绩者的信息。

说明:

1.学生结构体类型

 typedef struct Student {

       int num;

       char name[20];

       int score;

}STU; 

2.平均值保留2位小数;

3.输出最高成绩者信息时各项之间用“\t”隔开。

 

测试用例:输入

测试用例:输出

1< 回车 >          hangsan< 回车 >          86< 回车 >               2< 回车 >                lisi< 回车 >              84< 回车 >               3< 回车 >              wanger< 回车 >          93< 回车 >

 

The average score=87.67
The student who has the highest score is:
3       wanger  93

 


代码如下:

#include <stdio.h>

typedef struct Student {
	int num;
	char name[20];
	int score;
}STU; 

int main()
{
	STU student[3];
	int i, max = 0;
	double average = 0.0;
	for (i = 0; i < 3; ++i) {
		scanf("%d%s%d", &student[i].num, student[i].name, &student[i].score);
		average += student[i].score;
		if (student[i].score >= student[max].score) {
			max = i;
		}
	}
	average /= 3;
	printf("The average score=%.2lf\n", average);
	printf("The student who has the highest score is:\n");
	printf("%d\t%s\t%d", student[max].num, student[max].name, student[max].score);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值