再练习C语言二维数组函数时,定义了求每年降水总量,年平均降水量以及月平均降水量三个函数,通过GCC编译时出现expected expression before ‘float’报错,调式很久也无法解决,特来求助。
#include<stdio.h>
#define MONTHS 12
#define YEARS 5
void year_total(float ar[][MONTHS],int years,int months);
void year_average(float ar[][MONTHS],int years,int months);
void month_average(float ar[][MONTHS],int years,int months);
int main(void)
{
const float rain[YEARS][MONTHS]=
{
{4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
{8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
{9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
{7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
{7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
};
year_total(float rain[][MONTHS],5,12);
year_average(float rain[][MONTHS],YEARS,MONTHS);
month_average(float rain[][MONTHS],YEARs,MONTHS);
return 0;
}
void year_total(float ar[][MONTHS],int years,int months)
{
int n,k;
float sum;
for(n=0,sum=0.0;n<years;n++)
{
for(k=0;k<months;k++)
{
sum+=ar[n][k];
printf("THE %dyear is %lf inch\n",n,sum);
}
sum=0;
}
}
void year_average(float ar[][MONTHS],int years,int months)
{
int n,k;
float sum;
for(n=0,sum=0.0;n<years;n++)
{
for(k=0;k<months;k++)
sum+=ar[n][k];
}
printf("The yearly average is %lf inch",sum/years);
}
void month_average(float ar[][MONTHS],int years,int months)
{
int n,k;
float sum;
for(n=0,sum=0.0;n<years;n++)
{
for(k=0;k<months;k++)
sum+=ar[n][k];
}
printf("The yearly average is %lf inch",sum/(years*months));
}
以下是报错截图:
求各位帮忙解答一下,实在是苦恼。