C语言 编写一个函数print,输出一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录

Posted C语言大本营

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言 编写一个函数print,输出一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#define N 5
struct student
	char num[6];
	char name[8];
	int score[4];
stu[N];
void print(struct student stu[6])
	int i,j;
	printf("\\nNO. name score1 score2 score3\\n");
	for(i=0;i<N;i++)
		printf("%s%5s",stu[i].num,stu[i].name);
		for(j=0;j<3;j++)
			printf("%7d",stu[i].score[j]);
		printf("\\n");
	

int main()
	int i,j;
	for(i=0;i<N;i++)
		printf("\\nintput score of student %d:\\n",i+1);
		printf("NO.:");
		scanf("%s",stu[i].num);
		printf("name:");
		scanf("%s",stu[i].name);
		for(j=0;j<3;j++)
			printf("score %d:",j+1);
			scanf("%d",&stu[i].score[j]);
		
		printf("\\n");
	
	print(stu);
	return 0;

以上是关于C语言 编写一个函数print,输出一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录,用print函数输出这些记录的主要内容,如果未能解决你的问题,请参考以下文章