中易网

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

答案:2  悬赏:70  
解决时间 2021-04-27 10:00
  • 提问者网友:枯希心
  • 2021-04-27 05:03
每个记录包括num、name、score[3],并编写input函数用来输入数据记录,在主函数中输出这些记录。
最佳答案
  • 二级知识专家网友:颜值超标
  • 2021-04-27 05:20
#include
struct student {
int num;
int score[3];
char name[10];
};
void print(const struct student* stud, const int n)
{
int i, j;
for (i = 0; i < n; ++i) {
printf("num: %d\n", stud[i].num);
printf("name: %s\n", stud[i].name);
for (j = 0; j < 3; ++j) {
printf("score%d: %d\n", j + 1, stud[i].score[j]);
}
}

}
int main(void)
{
struct student stud[5]={...};
print(stud, 5);
return 0;
}
学生数据你自己填,可以将就用一下
全部回答
  • 1楼网友:随心随缘不随便
  • 2021-04-27 05:28
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); }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息