当我在.c文件中运行此代码时,它可以工作,但是当我为它创建一个项目时,我调用的函数将只返回0.00.为什么?为什么它不能在项目文件中工作?
我正在使用DevC++.
#include<stdio.h>
float mean(int total, int max);
int main(){
int i,max, total=0;
int array[max];
printf("Enter max: ");
scanf("%d",&max);
for(i=0; i<max; i++){
scanf("%d",&array[i]);
total+=array[i];
}
printf("Total: %d\n",total);
printf("Mean: %.2f",mean(total,max));
return 0;
}
float mean(int total, int max){
float ave;
ave=(float)total/max;
return ave;
}
Run Code Online (Sandbox Code Playgroud)