编写一个函数print

来源:百度知道 编辑:UC知道 时间:2024/06/28 13:30:39
编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num、name、score[3],用主函数输入这些记录,用print函数输出这些记录。

第二题,在上题的基础上编写一个函数input,用来输入5个学生的数据记录。

#include<stdio.h>
#define N 5
struct student
{
char num[20];
char name[20];
int score[3];
};
int main ()
{
void print(struct student stu[]);
struct student stu[N],*p=stu;
int i;
printf("请输入学生信息(学号 姓名 课1成绩 课2成绩 课3成绩)\n");
for(i=0;i<N;i++)
{
printf("请输入第%d个学生成绩:\n",i+1);
scanf("%s %s %d %d %d\n",stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
print(p);
return 0;
}

void print(struct student stu[])
{int i;
printf("学生成绩:\n学号 \t姓名 \t课1 \t课2 \t课3\n");
for(i=0;i<N;i++)
printf("%s \t%s \t%d \t%d \t%d\n",stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}

网上没用的,别老花高分到知道上边找啦,少的会有人愿意解决,多的谁也没时间去弄,最后还是自己弄的,经验之谈!