三个数求最大,小白才学,搞不懂编译器怎么工作的看看错哪了?
#include<stdio.h>
void main()
{
int a,b,c,d;
scanf("%d%d%d",&a,&b,&c);
d= max (a,b,c);
printf("max is %d",d);
}
int max(int x,int y,int z)
{
int w;
if(x>y) w=x;
else w=y;
if(z>w)w=z;
else return w;
}
1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\5\1.cpp(6) : error C2065: 'max' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\5\1.cpp(12) : error C2373: 'max' : redefinition; different type modifiers
[解决办法]
在主函数中加一个对max函数的声明,int max(int x,int y,int z);
另外把max函数中的最后一个else去掉。