#include<stdio.h>
typedef struct Student{
char name[31];
int age;
double score;
}Student;
void GetInfo(char*pname,int*page,double*pscore);
double getAverage(Student*parr,int length);
int main(void)
{
Student stus[3];
int i;
puts("请输入3个学生的信息,每项之间用空格隔开");
for(i=0;i<3;i++)
{
GetInfo(stus[i].name,&(stus[i].age),&(stus[i].score));
}
printf("平均分为:%lf\n",getAverage(stus,3));
return 0;
}
void GetInfo(char*pname,int*page,double*pscore)
{
while(3!=scanf("%s %d %lf",pname,page,pscore))
{
fputs("输入错误!\n",stderr);
while('\n'!=getchar());
}
}
double getAverage(Student*parr,int length)
{
double sum=0.0;
int i;
for(i=0;i<length;i++)
{
sum+=parr[i].score;
}
return sum/3.0;
}
不懂的可以再追问, : )