我正在使用函数解决最大和最小的代码。我写的代码是这样的:
#include <stdio.h>
int maxmin(int x, int y);
int main () {
int a, b, c;
scanf("%d%d", &a, &b);
c = maxmin(a, b);
if (maxmin == 1) {
printf("%d is maximum,%d is minimum", a, b);
}
else
printf("%d is maximum,%d is minimum", b, a);
return 0;
}
int maxmin(int x, int y) {
int XisMax = 0;
if (x > y) {
XisMax=1;
}
else {
XisMax=0;
}
return XisMax;
}
所以我的输出显示了这个结果:
Input:9,10;
10 is maximum,9 is minimum
Input:10,9;
9 is maximum,10 is minimum
这里有什么错误吗?我该怎么办?
PS:我有一个关于函数的考试,因此使用函数的解决方案会很有帮助。
最佳答案
如果(最大最小==1)
更改为if (c==1)
你的问题已经解决了。 祝你有美好的一天
关于C 程序使用函数查找两个数字之间的最大值和最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59035946/