用C++程序编写输入三角形的边长,判断它是否是直角三角形。

2025-04-28 02:45:51
推荐回答(2个)
回答1:

精度问题,只要把float修改为double即可。
参考代码如下:
#include
#include
using namespace std;
int main()
{
double a,b,c;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
if ((a*a+b*b==c*c)||(b*b+c*c==a*a)||(a*a+c*c==b*b))
cout<<"Yes,it's a right triangle."< else
cout<<"Sorry,it's not a right triangle."< system("pause");
return 0;
}

回答2:

浮点数判断相等不能用==,把if里的三个x==y格式的改成abs(x-y)<0.000001这种格式