编写一个函数print,输出一个学生的成绩数组,该数组中有5个学生的数据记录

每个记录包括num、name、score[3],并编写input函数用来输入数据记录,在主函数中输出这些记录。

第1个回答  推荐于2016-09-27
#include<stdio.h>

struct men
{
int num;
char name[8];
char sex[8];
float score;
}boy[5];

void input()
{
int i;
for(i=0;i<5;i++)
{
printf("Input the number:\n");
scanf("%d",&boy[i].num);
printf("Input the name:\n");
scanf("%s",boy[i].name);
printf("Input the sex:\n");
scanf("%s",boy[i].sex);
printf("Input the score:\n");
scanf("%f",&boy[i].score);
}
}

void output()
{
int i;
for(i=0;i<5;i++)
{
printf("NUM\t\t\tNAME\t\t\tSEX\t\t\tSCORE\n");
printf("%d\t\t\t",boy[i].num);
printf("%s\t\t\t",boy[i].name);
printf("%c\t\t\t",boy[i].sex);
printf("%.2f\n\n",boy[i].score);
}
}

int main()
{
void input();
void output();
input();
output();

return (0);
}本回答被提问者采纳
第2个回答  2012-05-21
struct student
{
int num;
char name[20];
float score[3];
}stu[5];
void input(struct student stu[5])
{
int i,j;
for(i=0;i<5;i++)
{
scanf("%d,%s",&stu[i].num,&stu[i].name);
for(j=0;j<3;j++)
scanf("%f",&stu[i].score[j]);
}
}
void output(struct student stu[5])
{
int i,j;
for(i=0;i<5;i++)
{
printf("%d,%s,",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%.2f,",stu[i].score[j]);
printf("\n");
}
}
main()
{
input(stu);
output(stu);
}
第3个回答  2010-05-12
自己写吧,完成之后,你会发现你懂了许多。