判断输入三个正整数是否构成直角三角形(是:Yes;不是:No;不构成三角形:Not a trangle)

#include <iostream>

using namespace std;
void judge_triangle(int L, int m, int s); // 若函数调用顺序和函数的编写不一致,需要声明函数
// 三数排序--从大到小
void trangle(int x, int y, int z)
{
if (x > y)
{
if (x > z)
{
if (z > y)
judge_triangle(x, z, y);
else
judge_triangle(x, y, z);
}
else if (x < z)
judge_triangle(z, x, y);
}
else if (y > z)
{
if (y > x)
{
if (x > z)
judge_triangle(y, x, z);
else
judge_triangle(y, z, x);
}
else if (y < x)
judge_triangle(x, y, z);
}
else if (z > x)
{
if (z > y)
{
if (y > x)
judge_triangle(z, y, x);
else
judge_triangle(z, x, y);
}
else if (z < y)
judge_triangle(y, z, x);
}
}

void judge_triangle(int L, int m, int s)
{
if ((m + s) <= L || (L - m) >= s)
printf("Not a Triangle\n");
else
if ((m * m + s * s) == L * L)
printf("Yes\n");
else
printf("No\n");
}

int main()
{
int L, m, s;
while (true) {
printf("请输入构成三角形的三条边:");
cin >> L >> m >> s;
trangle(L, m, s);
printf("\n");
}
return 1;
}

猜你喜欢

转载自www.cnblogs.com/TyranRex/p/12157951.html