题目是:
输入三个点坐标
若该三点能构成三角形则输出周长和面积,否则输出Impossible;
现在只能输出Impossible。
#include
int main()
{
double a,b,c,d,e,f,g,h,i,k;
scanf("%lf,%lf\n",&a,&b);
scanf("%lf,%lf\n",&c,&d);
scanf("%lf,%lf\n",&e,&f);
g=sqrt((a-c)*(a-c)-(b-d)*(b-d));
h=sqrt((c-e)*(c-e)-(d-f)*(d-f));
i=sqrt((a-e)*(a-e)-(b-f)*(b-f));
if(g+h&&g+i&&i+h"primer=%.2f,area=%.2f",g+h+i,sqrt(k*(k-g)*(k-h)*(k-i)));
}else{
printf("Impossible");
}
return 0;
}
计算两点间距离有误,应该是相加,不是相减
g=sqrt((a-c)*(a-c)+(b-d)*(b-d));
h=sqrt((c-e)*(c-e)+(d-f)*(d-f));
i=sqrt((a-e)*(a-e)+(b-f)*(b-f));
#include<stdio.h>
#include<math.h>
int main(void)
{
double x1,y1,x2,y2,x3,y3;
double l1,l2,l3;
double L,A;
scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
l1=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
l2=sqrt(pow((x2-x3),2)+pow((y2-y3),2));
l3=sqrt(pow((x1-x3),2)+pow((y1-y3),2));
if(l1+l2>l3&&l1+l3>l2&&l2+l3>l1){
L=l1+l2+l3;
float p=L/2.0;
A=sqrt(p*(p-l1)*(p-l2)*(p-l3));
printf("L = %.2f, A = %.2f",L,A);
}
else
printf("Impossible");
return 0;
}