C语言一道题目改错,总是 error: too many initializers for `student'
答案:1 悬赏:60 手机版
解决时间 2021-02-05 11:08
- 提问者网友:临风不自傲
- 2021-02-04 14:53
C语言一道题目改错,总是 error: too many initializers for `student'
最佳答案
- 五星知识达人网友:北方的南先生
- 2021-02-04 15:03
#include
struct score
{
int math;
int english;
int chinese;
};
struct student
{
int num;
char name[10];
struct score course;
int average;
}stu[10] = {
{ 10101, "Li", { 90, 85, 89 }, 88 },
{ 10102, "Zhang", { 80, 80, 80 }, 80 },
{ 10103, "Wang", { 90, 90, 90 }, 90 },
{ 10104, "Zhao", { 100, 100, 100 }, 100 }
};
int main()
{
int i;
float aver;
for (i = 0; i < 5; i++)
printf("%5d %s %5d%5d%5d
", stu[i].num, stu[i].name, stu[i].course.math, stu[i].course.english, stu[i].course.chinese);
for (i = 0; i < 5; i++)
{
stu[i].average = (stu[i].course.math + stu[i].course.english + stu[i].course.chinese) / 3;
printf("第%d个学生的平均成绩:%d
", i, stu[i].average);
}
}
struct score
{
int math;
int english;
int chinese;
};
struct student
{
int num;
char name[10];
struct score course;
int average;
}stu[10] = {
{ 10101, "Li", { 90, 85, 89 }, 88 },
{ 10102, "Zhang", { 80, 80, 80 }, 80 },
{ 10103, "Wang", { 90, 90, 90 }, 90 },
{ 10104, "Zhao", { 100, 100, 100 }, 100 }
};
int main()
{
int i;
float aver;
for (i = 0; i < 5; i++)
printf("%5d %s %5d%5d%5d
", stu[i].num, stu[i].name, stu[i].course.math, stu[i].course.english, stu[i].course.chinese);
for (i = 0; i < 5; i++)
{
stu[i].average = (stu[i].course.math + stu[i].course.english + stu[i].course.chinese) / 3;
printf("第%d个学生的平均成绩:%d
", i, stu[i].average);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯