已知三个点坐标判断三角形是什么形状的C++语言怎么写啊
发布网友
发布时间:2023-10-17 10:06
我来回答
共3个回答
热心网友
时间:2024-11-26 18:24
我帮你运行了,没有出错啊,不是只是钝角啊。#include<iostream.h>
#include<math.h>
void main()
{
double x1;
double y1;
double x2;
double y2;
double x3;
double y3;
cout << "x1=";
cin >> x1;
cout << "y1=";
cin >> y1;
cout << "x2=";
cin >> x2;
cout << "y2=";
cin >> y2;
cout << "x3=";
cin >> x3;
cout << "y3=";
cin >> y3;
double z1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double z2=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
double z3=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
double p=(z1+z2+z3)/2;
double s=sqrt(p*(p-z1)*(p-z2)*(p-z3));
double a=(z1*z1+z2*z2-z3*z3);
double b=(z2*z2+z3*z3-z1*z1);
double c=(z3*z3+z1*z1-z2*z2);
cout << "面积s=" << s << endl;
if (a*b*c>0)
cout<<"锐角三角形";
if (a*b*c==0)
cout<<"直角三角形";
if (a*b*c<0)
cout<<"钝角三角形";
}
热心网友
时间:2024-11-26 18:24
我帮你运行了,没有出错啊,不是只是钝角啊。#include<iostream.h>
#include<math.h>
void
main()
{
double
x1;
double
y1;
double
x2;
double
y2;
double
x3;
double
y3;
cout
<<
"x1=";
cin
>>
x1;
cout
<<
"y1=";
cin
>>
y1;
cout
<<
"x2=";
cin
>>
x2;
cout
<<
"y2=";
cin
>>
y2;
cout
<<
"x3=";
cin
>>
x3;
cout
<<
"y3=";
cin
>>
y3;
double
z1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double
z2=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
double
z3=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
double
p=(z1+z2+z3)/2;
double
s=sqrt(p*(p-z1)*(p-z2)*(p-z3));
double
a=(z1*z1+z2*z2-z3*z3);
double
b=(z2*z2+z3*z3-z1*z1);
double
c=(z3*z3+z1*z1-z2*z2);
cout
<<
"面积s="
<<
s
<<
endl;
if
(a*b*c>0)
cout<<"锐角三角形";
if
(a*b*c==0)
cout<<"直角三角形";
if
(a*b*c<0)
cout<<"钝角三角形";
}
热心网友
时间:2024-11-26 18:25
double a=(z1*z1+z2*z2-z3*z3);
z1 z2为短边,z3要长边才行
还要排序啊