C语言,此类型题,即调用因变量会不断变化的函数.为什么输出不对啊?题目: Write a program that readsthree pairs of numbers and adds the larger of the first pair, the larger of thesecond pair and the larger of the third pair.
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/03 11:23:22
C语言,此类型题,即调用因变量会不断变化的函数.为什么输出不对啊?题目: Write a program that readsthree pairs of numbers and adds the larger of the first pair, the larger of thesecond pair and the larger of the third pair.
C语言,此类型题,即调用因变量会不断变化的函数.为什么输出不对啊?
题目:
Write a program that readsthree pairs of numbers and adds the larger of the first pair, the larger of thesecond pair and the larger of the third pair. Use a function to return thelarger of each pair.
# include
#include
int max(float x,float y)
{
float z;
z=x>y?x:y;
return(z);
}
int main()
{
float a,b,c,d,e,f;
scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f);
printf("Max is %d\n",max(a,b));
printf("Max is %d\n",max(c,d));
printf("Max is %d\n",max(e,f));
printf("%d",max(a,b)+max(c,d)+max(e,f));
system("pause");
return 0;
}
C语言,此类型题,即调用因变量会不断变化的函数.为什么输出不对啊?题目: Write a program that readsthree pairs of numbers and adds the larger of the first pair, the larger of thesecond pair and the larger of the third pair.
1、int max(float x,float y) 修改为float max(float x,float y);
2、注意,输入的格式要与scanf()的格式保持一致.
既然你的输入方式是用逗号隔开每个数字,则scanf的格式也要这么写:
scanf("%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&e,&f);
3、打印的格式是%f,不是%d;后者是打印整数的.