输出结果都是第一个数,是哪里错了
[local]1[/local][code
]#include <stdio.h>
max(float x,float y)
{
float z;
z=x>y?x:y;//这里错了吗?不是输出较大值吗
return(z);
}
main()
{
float a,b;
int c;
scanf("%f,%f",&a,&b);
c=max(a,b);
printf("max is %d\n",c);
}[/code]
程序代码:#include <stdio.h>
float max(float x,float y) //函数返回类型应该是float型
{
float z;
z=x>y?x:y;//这里错了吗?不是输出较大值吗
return(z);
}
int main() //main函数前应该加int ,函数最后应该加return
{
float a,b,c;
scanf("%f,%f",&a,&b); //输入的时候应该输入 x,y 中间不能使用空格或者其他字符,否则scanf读取第二个参数的时候因类型不匹配二返回错误。
c=max(a,b); //返回的float类型要使用float类型接收
printf("max is %f\n",c); //输出float类型应该使用%f
return 0;
