利用结构体套数组输出
#include<stdio.h>
struct Students{
int numb;
float resault[3];
};
int main()
{
int i ,j;
struct Students st[4];
struct Students *p;
p = &st;
for(i = 0 ; i < 4 ; i++)
{
printf("第%d名学生的三门成绩:",i+1);
scanf("%f%f%f",&st[i].resault[0],&st[i].resault[1],&st[i].resault[2]);
}
printf("请输入学号:");
scanf("%d",&j);
printf("%d学号的成绩为:%0.2f,%0.2f,%0.2f",j,st[j-1].resault[0],st[j-1].resault[1],st[j-1].resault[2]);
return 0;
}
出现一次错误
printf("%d学号的成绩为:%d,%d,%d",j,st[j-1].resault[0],st[j-1].resault[1],st[j-1].resault[2]);
给输出语句%d,是实现整数的输出,而定义的是float浮点数,所以输出的是0.0000,而不是输入的1.