c语言 来教教我哪里不对啊

2025-06-26 17:21:10
推荐回答(1个)
回答1:

#include "stdio.h"
float average(int a ,int b,int c)//①因为平均数易出小数,用int类型不合适,所以将函数的返回值的类型改为float型;
//②变量y不能出现在参数中,另外int,y的写法不正确。
{
// return (a+b+c)/3,这一句要放到函数的最后
// a=10; b=20; c=30? abc是函数的参数,它们在主函数中赋值;句末不能用问号,只能用分号(;)。
float y;
y=(a+b+c)/3.0; //除数改为3.0;
//printf("\n (a+b+c)/3",y); getchar(); 这两句放到主函数中去。
return y;
}
main()//增加主函数
{
int a=10; b=20; c=30;
printf("(%d+%d+%d)÷3=%f\n",a,b,c,average(a,b,c));//打印语句,注意平均值是调用函数求出来的
getchar();
}