august 发表于 2007-5-24 07:42:53

结构输出的问题

程序如下:
#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);

      
      

}
为什么最后的那个函数无法输出正确的值呢?应该怎么写??

Saiholmes 发表于 2007-5-24 08:03:08

1.float b=0;
2.for(k=0;k<=1;k++)
3.printf("第一学生总成绩%f\\n",b);

august 发表于 2007-5-24 08:06:54

好像不是这样吧,这样直接输出0,好像b=b+num.score,传不到值给b?

Zelsazgh 发表于 2007-5-24 15:38:23

最后一句输出时格式化输出时出错了
改成
printf("第一学生总成绩%f",b);
页: [1]
查看完整版本: 结构输出的问题