已在函数中声明但却被判定为未声明
共十个学生,每名学生五门课程,这个小程序是用来输出每名学生的平均成绩、每门课程的平均成绩、获取最高分数的人和该科以及学生的平均分方差。代码如下:
#include<stdio.h>
#include<math.h>
void test1(double students[10][5],double average_stu[10]);
void test2(double students[10][5],double average_sub[5]);
void test3(double students[10][5]);
void test4(double average_stu[10]);
int main()
{
int i,j;
char x;
double students[10][5];
double average_stu[10];
double average_sub[5];
ABC:
printf("would you want to test ?(y/Y or n/N):");
scanf("%c",&x);
if(x=='n'||x=='N') return 0;
printf("please input the students' score:\n");
for(i=0;i<=9;i++)
{
for(j=0;j<=4;j++) scanf("%lf",&students[i][j]);
}
test1(students,average_stu);
test2(students,average_sub);
test3(students);
test4(average_stu);
printf("the END\n");
goto ABC;
return 0;
}
void test1(double students[10][5],double average_stu[10])
{
printf("the average score of the students\n");
int i,j;
double sum=0;
for(i=0;i<=9;i++)
{
sum=0;
for(j=0;j<=4;j++)
{
sum=sum+students[i][j];
}
average_stu[i]=sum/5;
}
for(i=0;i<=9;i++) printf("the student%d\t%lf\n",i+1,average_stu[i]);
printf("--------------------------------------------------------------------\n");
}
void test2(double students[10][5],double average_sub[5])
{
printf("the average score of subject\n");
int i,j;
double sum=0;
for(j=0;j<=4;j++)
{
sum=0;
for(i=0;i<=9;i++) sum=sum+students[i][j];
average_sub[j]=sum/10;
}
for(i=0;i<=4;i++) printf("the subject%d\t%lf\n",i+1,average_sub[i]);
printf("--------------------------------------------------------------------\n");
}
void test3(double students[10][5])
{
printf("the high subject and student\n");
double max;
int i,j,m,n;
max=students[0][0];
for(i=0;i<=9;i++)
{
for(j=0;j<=4;j++)
{
if(max<students[i][j])
{
max=students[i][j];
m=i;
n=j;
}
}
}
printf("the NO1 is student%d's subject%d\t%lf\n",m+1,j+1,max);
printf("--------------------------------------------------------------------\n");
}
void test4(double average_stu[10])
{
printf("the var score of this class\n");
double sum=0,var,sum1=0;
int i;
for(i=0;i<=9;i++)
{
sum=sum+pow(average_stu[i],2);
sum1=sum1+average_stu[i];
}
sum1=pow(sum1/10,2);
var=sum/10-sum1;
printf("the var of the students' score is %lf\n",var);
printf("--------------------------------------------------------------------\n");
}
现在问题是:我已经在函数体中声明了这些变量(上面我描红的地方),但编译时判定为未声明
而后我将这些变量全部声明为全局变量,这样编译才通过,这是什么原因呢?
ps:我在以c++格式编译时能够通过(因为我的编译器默认是首先以.cpp文件编译的,后来我将其保存为.c文件才发现问题)