给定平面上任意三个点的坐标(x1,y1)、(x2,y2)、(x3,y3),检验它们能否构成三角形

2024-11-15 06:20:04
推荐回答(3个)
回答1:

#include
#include

int main()
{ double a,b,c,d,e,f;
scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f );
double AB,BC,AC,ab,bc,ac;
ab=(a-c)*(a-c)+(b-d)*(b-d);
bc=(c-e)*(c-e)+(d-f)*(d-f);
ac=(a-e)*(a-e)+(b-f)*(b-f);
AB=sqrt(ab);
BC=sqrt(bc);
AC=sqrt(ac);
if((AB {
double l=AB+BC+AC;
double P = l / 2;
double s = sqrt(P*(P-AB)*(P-BC)*(P-AC));
printf("L = %.2f, A = %.2f",l,s); }
else
{printf ("Impossible");
}
return 0;
}

大概是你判断太多了,上面这个是一个可以通过的程序

回答2:

#include
#include
#include
using namespace std;
int main(){
double x[3],y[3];
double l[3],p,s;
int b=0;
for(int i=0;i<3;i++){
cin>>x[i]>>y[i];
}
for(int i=0;i<2;i++){
for(int j=i+1;j<3;j++)
{
l[b]=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
b++;}
}
if(l[0]+l[1]>l[2]&&l[0]+l[2]>l[1]&&l[1]+l[2]>l[0]){
p=(l[0]+l[1]+l[2])/2;
s=sqrt(p*(p-l[0])*(p-l[1])*(p-l[2]));
cout<cout<<"L = "<}
}

回答3:

#include
#include

int main()
{ double a,b,c,d,e,f;
scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f );
double AB,BC,AC,ab,bc,ac;
ab=(a-c)*(a-c)+(b-d)*(b-d);
bc=(c-e)*(c-e)+(d-f)*(d-f);
ac=(a-e)*(a-e)+(b-f)*(b-f);
AB=sqrt(ab);
BC=sqrt(bc);
AC=sqrt(ac);
if((AB{
double l=AB+BC+AC;
double P = l / 2;
double s = sqrt(P*(P-AB)*(P-BC)*(P-AC));
printf("L = %.2f, A = %.2f",l,s); }
else
{printf ("Impossible");
}
return 0;
}