结构输出的问题
程序如下:#include<stdio.h>
#include<stdlib.h>
struct stud
{
int num;
char name;
float score;
}student;
void main()
{
void abc(struct stud numb[]);
int i,j;
char number;
for(i=0;i<2;i++)
{
gets(number); student.num=atoi(number);
gets(student.name);
for(j=0;j<3;j++)
{
gets(number); student.score=atof(number);
}
}
printf("\n num name score1 score2 score3\n");
for(i=0;i<2;i++)
{
printf("%2d%8s ",student.num,student.name);
for(j=0;j<3;j++)
printf("%18f",student.score);
printf("\n");
}
abc(student);
}
void abc(struct stud numb[])
{
float b,c;
int k,l;
for(k=0;k<1;k++)
{
for(l=0;l<3;l++)
b=b+numb.score;
}
printf("第一学生总成绩%d\n",b);
}
为什么最后的那个函数无法输出正确的值呢?应该怎么写?? 1.float b=0;
2.for(k=0;k<=1;k++)
3.printf("第一学生总成绩%f\\n",b); 好像不是这样吧,这样直接输出0,好像b=b+num.score,传不到值给b? 最后一句输出时格式化输出时出错了
改成
printf("第一学生总成绩%f",b);
页:
[1]