#include <iostream> #include <math.h> using namespace std; void max_min(int a, int b, int c) { int m; if (a > b) { m = a; a = b; b = m; } if (a > c) { m = a; a = c; c = m; } if (b > c) { m = b; b = c; c = m; } } int main() { int t; int a, b ,c; cin >> t; for (int i = 1; i <= t; i ++) { cin >> a >> b >> c; max_min(a, b, c); if (a == b && b == c) cout << "equilateral" << endl; else if (pow (c, 2) == pow (a, 2) + pow (b, 2)) cout <<"right" << endl; else if (c >= a + b) cout << "error" << endl; else cout << "normal" << endl; } return 0; }为什么我的max_min函数不管用
时间: 2023-12-22 22:03:23 浏览: 66
使用include <iostream>时一定要加using namespace std
你的max_min函数没有返回值,也没有改变a,b,c的值,因此在main函数中使用max_min函数并不会产生任何影响。你需要修改max_min函数,让它返回三个参数的最大值和最小值,然后在main函数中使用这些返回值来判断三角形的类型。以下是修改后的代码:
```c++
#include <iostream>
#include <math.h>
using namespace std;
void max_min(int a, int b, int c, int& max_val, int& min_val) {
int m;
if (a > b)
{
m = a;
a = b;
b = m;
}
if (a > c)
{
m = a;
a = c;
c = m;
}
if (b > c)
{
m = b;
b = c;
c = m;
}
max_val = c;
min_val = a;
}
int main() {
int t;
int a, b, c;
cin >> t;
for (int i = 1; i <= t; i ++)
{
cin >> a >> b >> c;
int max_val, min_val;
max_min(a, b, c, max_val, min_val);
if (a == b && b == c)
cout << "equilateral" << endl;
else if (pow(c, 2) == pow(a, 2) + pow(b, 2))
cout << "right" << endl;
else if (c >= a + b)
cout << "error" << endl;
else
cout << "normal" << endl;
}
return 0;
}
```
阅读全文