程序目的 输入3个学生的三科成绩 计算平均分 并输出
哪里有错?
#include<stdio.h>
void print(struct student *p);
struct student *inpu(struct student *p);
float count(struct student *p);
struct student
{
char name[10];
float mark[3];
float average;
};
main()
{
int i=0;
struct student stu[3],*p=stu;
p=inpu(p);
while(i<3)
(p+i)->average=count(p+i);
print(p);
}
struct student *inpu(struct student *p)
{
int i;
printf("输入学生姓名极其成绩:\n");
printf("姓名\t语文\t数学\t英语\n");
for(i=0;i<3;i++)
scanf("%s%f%f%f",(p+i)->name,&((p+i)->mark[0]),&((p+i)->mark[1]),&((p+i)->mark[2]));
return p;
}
float count(struct student *p)
{
p->average=(p->mark[0]+p->mark[1]+p->mark[2])/3;
return p->average;
}
void print(struct student *p)
{
int i=0;
printf("输出学生成绩\n");
printf("姓名\t语文\t数学\t英语\n");
while(i<3)
{
printf("%s\t%f\t%f\t%f\n",(p+i)->name,(p+i)->mark[0],(p+i)->mark[1],(p+i)->mark[2]);
i++;
}
}