DHU OJ | 基本练习-80 平均分 | 结构体

27 篇文章 1 订阅

80 平均分

作者: 江宝钏时间限制: 1S章节: 结构体

问题描述 :

从键盘依次输入每个学生的学号、姓名、出生年月、3门课的成绩,计算并打印出每个学生的平均成绩。

要求使用结构体数组。

 

输入说明 :

第一行,整数n,表示一共有n个学生。

从第二行开始共n行,每行包含学号,姓名,出生年,出生月,数学,英语,C语言的成绩,用空格分隔,姓名不含空格。

输出说明 :

共n行,每行包含学号,姓名,出生年/月,数学,英语,C语言,平均成绩。

输出浮点数使用“%.0f”,出生年月用“/”分开,数据之间以一个空格分隔。

输入范例 :

2
901 hulei 1990 8 67 78 89
902 fangang 1991 7 85 69 76

输出范例 :

901 hulei 1990/8 67 78 89 78
902 fangang 1991/7 85 69 76 77
 

笔记

特别注意,在创建结构体变量时,要在结构体名称前加上“struct”

struct student{
	int no;
	char name[10];
	int birth_y;
	int birth_m;
	int math_score;
	int e_score;
	int c_score;
};
struct student stu;

否则会出现编译错误。

代码

#include<stdio.h>
struct student{
	int no;
	char name[10];
	int birth_y;
	int birth_m;
	int math_score;
	int e_score;
	int c_score;
};

int main(){
	int n;
	scanf("%d",&n);
	
	int i;
	struct student stu;
	int avg_score = 0;
	for(i=0;i<n;i++){
		scanf("%d %s %d %d %d %d %d",
     &stu.no,stu.name,&stu.birth_y,&stu.birth_m,&stu.math_score,&stu.e_score,&stu.c_score);
		printf("%d %s %d/%d %d %d %d %.0f\n",
		stu.no,stu.name,stu.birth_y,stu.birth_m,stu.math_score,stu.e_score,stu.c_score,
				1.0*(stu.math_score+stu.e_score+stu.c_score)/3);
	}
	
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值