C语言,此类型题,即调用因变量会不断变化的函数.为什么输出不对啊?
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/09/23 05:25:11
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;
}
题目:
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;
}
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;后者是打印整数的.
2、注意,输入的格式要与scanf()的格式保持一致.
既然你的输入方式是用逗号隔开每个数字,则scanf的格式也要这么写:
scanf("%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&e,&f);
3、打印的格式是%f,不是%d;后者是打印整数的.
一个C语言题,调用一个函数利用这个函数比较所输入的两个数大小,输出较小的值,如果两数相等输出相等!
C语言怎样用函数的递归调用法输出斐波那栔数列,
谁会用C语言 写“定义函数返回两个数中较大的数,在主函数中调用并输出.编写主函数调用该函数”.
设计一个可以输出任意行数的等腰三角形的函数,并编写main函数调用该函数.c语言
用C语言编写一个计算n!的函数,用主函数调用它,使之输出7阶杨辉三角形.
任意输入一个4位自然数,调用C 语言函数输出该自然数的各位数字组成的最大数
C语言里sin函数和cos函数的调用
C语言中函数调用,为什么交换了地址,可是所指的值还是不变那?
函数表示两个变量之间的关系.因变量(函数)随变量(自变量)的变化而变化.为什么说因变量(函数)
c语言编程 要求在main函数中调用子函数来输出菱形
函数不懂!假如 X=18-y 为什么Y是自变量 X是因变量 明明X变化Y也会变化啊 Y变化X也会变化!
C语言:在主函数中输入x,y,调用函数求出X,y的和,差,商,积,并在主函数中对他们输出