|
发表于 2023-10-18 20:46:28
|
显示全部楼层
您的代码中存在一些错误。以下是修正后的代码:
- #include<iostream>
- using namespace std;
- int min(int a, int b)
- {
- return a < b ? a : b;
- }
- int max(int a, int b)
- {
- return a > b ? a : b;
- }
- int main()
- {
- int a, b, c;
- cin >> a >> b >> c;
- int temp1 = a;
- int temp2 = b;
- int temp3 = c;
- a = min(min(temp1, temp2), temp3);
- c = max(max(temp1, temp2), temp3);
- b = temp1 + temp2 + temp3 - a - c;
- cout << a << " " << b << " " << c << endl;
- return 0;
- }
复制代码
以下是我对您的代码进行修改的地方:
1. 在cin语句中,您不需要包含空格和endl。只需要使用>>运算符将输入分配给变量即可。
2. 在调用min和max函数时,您需要分别调用两次,以便在三个数中找到最小值和最大值。在原始代码中,您使用了逗号运算符(temp1, temp2),这实际上会返回temp2,因此您的min和max函数实际上只在temp2和temp3之间进行比较。
3. 在min和max函数中,您不需要修改参数a。您可以直接返回比较的结果。
请注意,本回答来自GPT-4
如果问题已经解决,请设置最佳答案 |
|