问题 D: C语言11.7——编写两个函数input和print,分别用来输入5个学生的数据记录和打印这5个学生的记录。

题目描述:
编写两个函数input和print,分别用来输入5个学生的数据记录和打印这5个学生的记录。对于每一个学生,其记录包含了学号、名字、3门课程的成绩共5项。用主函数分别调用input和print函数进行输入和输出。
要求使用结构体数组实现,结构体中包括了每个学生的5项记录。

输入:
共有5行,每行包含了一个学生的学号(整数)、名字(长度不超过19的无空格字符串)和3门课程的成绩(0至100之间的整数),用空格隔开。

输出:
与输入格式相同,每行输出一个学生的所有记录。
请注意行尾输出换行。

样例输入:

101 AAA 80 81 82
102 BBB 83 84 85
103 CCC 86 87 88
104 DDD 89 90 91
105 EEE 92 93 94

样例输出:

101 AAA 80 81 82
102 BBB 83 84 85
103 CCC 86 87 88
104 DDD 89 90 91
105 EEE 92 93 94

代码:

#include <iostream>
using namespace std;
struct student{
	int num;
	char name[10];
	int sco1,sco2,sco3;
}student[5];
void input() {
	for(int i=0;i<5;i++){
		scanf("%d %s %d %d %d",&student[i].num,&student[i].name,&student[i].sco1,&student[i].sco2,&student[i].sco3);
	}
	return;
}
void print(){
	for(int i=0;i<5;i++){
		printf("%d %s %d %d %d\n",student[i].num,student[i].name,student[i].sco1,student[i].sco2,student[i].sco3);
	}
	return;
}
int main(){
	#ifdef ONLINE_JUDGE
	#else
		freopen("in.txt","r",stdin);
	#endif
	input();
	print();
	return 0;
} 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值