有2个学生,每个学生的数据包括学号、姓名、2门课的成绩,声明结构体类型,定义结构体变量,输出每个学生的信息。
struct student
char num 6];
char name 8];
int score1;
int scorc2;
)stu [2]={{"101"."Zhou"93,89),{"102","Yang",85,80}};
供参考:
#include <stdio.h>
struct student {
char num[6];
char name[8];
int score1;
int score2;
}stu[2] = { {"101","Zhou",93,89},{"102","Yang",85,80} };
int main()
{
int i;
for (i = 0; i < 2; i++)
printf("%s %s %d %d\n", stu[i].num, stu[i].name, stu[i].score1, stu[i].score2);
return 0;
}