求助,为什么用函数时不能返回正确数值?
代码如下:
#include <math.h>
main()
{
float a,b,c,last;
float max();
printf("Please input three numbers:");
scanf("%f,%f,%f",&a,&b,&c);
last=max(a,b,c);
printf("\nThe max number is:%f\n",last);
}
float max(float x,float y,float z)
{
if((x-y)>0)
if((x-z)>0)
return(x);
else
return(z);
else
if((y-z)>0)
return(y);
else
return(z);
}
以上代码无法得到正确结果,但用下面的代码即可:
#include <math.h>
main()
{
float a,b,c,last;
printf("Please input three numbers:");
scanf("%f,%f,%f",&a,&b,&c);
if((a-b)>0)
if((a-c)>0)
last=a;
else
last=c;
else
if((b-c)>0)
last=b;
else
last=c;
printf("\nThe max number is:%f\n",last);
}
求高人指点
[解决办法]
函数没定义,还有你的格式真的很不好,虽然说只有一行,但是加上{}眼睛会爽一些...
- C/C++ code
#include <math.h>void main(){ float a, b, c, last; float max(); float max(float x,float y,float z); //未定义函数 printf("Please input three numbers:"); scanf("%f,%f,%f",&a,&b,&c); last=max(a,b,c); printf("\nThe max number is:%f\n",last);}float max(float x, float y, float z){ if((x - y) > 0) { if((x - z) > 0) { return(x); } else { return(z); } else { if((y - z) > 0) { return(y); } else { return(z); } }}