|
发表于 2023-10-18 20:46:23
|
显示全部楼层
代码错误:
该代码有以下几个错误:
1. 在输入部分,使用了错误的语法。cin 语句应该为 cin >> a >> " " >> b >> " " >> c;。删除 endl。
2. 在调用 min 和 max 函数时,使用了错误的语法。应该为 a = min(min(temp1, temp2), temp3); 和 c = max(max(temp1, temp2), temp3);。
3. 在最后的 cout 语句中,多了一个不必要的 . 字符。
修改后的代码如下:
- #include<iostream>
- using namespace std;
- int min(int a, int b)
- {
- a = a < b ? a : b;
- return a;
- }
- int max(int a, int b)
- {
- a = a > b ? a : b;
- return a;
- }
- 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;
- }
复制代码
修改后的代码修复了语法错误,并且可以正确输出三个数的最小、中间和最大值。
希望对你有帮助!如果还有其他问题,请随时提问。
球一个最佳答案谢谢啦!这对我非常重要!   |
|