C语言任意输入三点求三角形面积周长，并判断其合法性
``````#include<stdio.h>
#include<math.h>
int main(void)
{
double p,a,b,c,primter,area,s;
float x1,y1,x2,y2,x3,y3;
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x2-x3)*(x2-x3)+(y1-y2)*(y1-y2));
c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
if((a<b+c)&&(b<a+c)&&(c<a+b)){
p=(a+b+c)/2;
s=p*(p-a)*(p-b)*(p-c);
primter=a+b+c;
area=sqrt(s);
printf("primter=%.2f",primter);
printf("area=%.2f",area);
}
else{
printf("Impossible\n");
}
return 0;
}
``````
``````#include<stdio.h>
#include<math.h>
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<BC+AC)&&(BC<AB+AC)&&(AC<AB+BC))
{
double l=AB+BC+AC;
double P = l / 2;
double s = sqrt(P*(P-AB)*(P-BC)*(P-AC));
printf("primter = %.2f, area = %.2f",l,s); }
else
{printf ("Impossible");
}
return 0;}
``````

1个回答

b=sqrt((x2-x3)*(x2-x3)+(y1-y2)*(y1-y2));

b=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));