帮我看个求平均值的C程序。

来源:百度知道 编辑:UC知道 时间:2024/06/20 00:43:46
#include<stdio.h>
main()
{
float a,b,c,aver;
a=6;b=7;c=3.9;
aver=average3(a,b,c);
printf("6,7,3.9 zhe3geshudepingjunzhi=%d",aver);
getch()
}
float average3(x,y,z)
float x,y,z;
{
float aver;
aver=(x+y+z)/3;
return(aver);
}
这是我在书上的的程序,我输入到tc c++3.0里面运行但是有错误。刚初学不太懂。哪里错了?改正下!

c是float型的,而3.9默认是double型,double型不能自动转换成float

另外,函数没有声明就使用也是不行的哦。

计算函数的前两行改为:float averagd3(float x,float y,float z) 在tc2.0里,浮点数做除法有漏洞,3.0就不清楚了,先这样改试试。