80 平均分

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
 

#include <stdio.h>
#include <string.h>

typedef struct student
{
	int stu_id;
	char name[20];
	int year;
	int month;
	int math;
	int english;
	int c_language;
}student;

int main()
{
	int n;
	float avg;
	scanf("%d",&n);
	while(n--)
	{
		student stu;
		scanf("%d %s %d %d %d %d %d",&stu.stu_id,stu.name,&stu.year,&stu.month,&stu.math,&stu.english,&stu.c_language);
		avg=(stu.english+stu.math+stu.c_language)/3.0;
		printf("%d %s %d/%d %d %d %d %.0f\n",stu.stu_id,stu.name,stu.year,stu.month,stu.math,stu.english,stu.c_language,avg);
	}
}

猜你喜欢

转载自blog.csdn.net/HurryBen/article/details/105720210
80
今日推荐