关于函数参数传递
#include "stdio.h"#include "conio.h"
#define N 3
struct student
{char num[6];
char name[8];
int score[3];
}stu[N]; ||这个是不是相当于一个全局变量?为什么在input函数里输入该值后不能传递到aver函数中?
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 aver(struct student stu[N])
{int average[3],sum[3]={0},i,j;
for(j=0;j<3;j++)
{
for(i=0;i<N;i++)
{sum[j]=sum[j]+stu[N].score[j];}
average[j]=sum[j]/N;
printf("average of score%d is %d.\n",j+1,average[j]);
}
}
main()
{input();
aver(stu);
getch();
}