关于函数值传递问题
#include "stdio.h"#include "conio.h"
#define N 2
struct student
{char num[6];
char name[8];
int score[3];
}stu[N];
void input()
{int i,j;
for(i=0;i<N;i++)
{printf("student%d:\n",i+1);
printf("Input num:");
scanf("%s",&stu[i].num);
printf("Input name:");
scanf("%s",&stu[i].name);
for(j=0;j<3;j++)
{printf("input score%d:",j+1);
scanf("%d",&stu[i].score[j]);
}
}
}
void aver1(struct student stu[N])
{int i,j;
float *average1[3],sum[3]={0};
for(j=0;j<3;j++)
{
for(i=0;i<N;i++)
{sum[j]=sum[j]+stu[i].score[j];}
*average1[j]=sum[j]/N; ||我要将该函数中计算出来的均值,传递到print函数中使用,该怎么实现啊?
}
}
void print(struct student stu[N])
{int i;
aver1(stu);
printf("\nNO. name score1 score2 score3\n");
for(i=0;i<N;i++)
{printf("%3s%5s%8d%8d%8d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);}
printf("average:%10f%8f%8f",*average1[0],*average1[1],*average1[2]); ||用指针,这样写可以吗
}
main()
{input();
aver1(stu);
print(stu);
getch();
}