这算一道简单的编程题目吗?

2025-12-06 11:15:07
推荐回答(1个)
回答1:

输入三点。
求出三边的长度L,L1,L2。
找出最长的一条边L;作这条边的高;此时这条边一半设为X,另一边为L-X;所以得到-X^2+L1^2=-(L-X)^2+L2^2;解得X值,也就求得高H的值.
三角形的面积=L×H/2。
注意:输入坐标的格式。这里的格式是:A,A1;B,B1;C,C1

#include "stdio.h"
#include "math.h"
void main()
{
float area=0,L=0,L1=0,L2=0,H=0;
int a,a1,b,b1,c,c1;
printf("pleae input the three point\n");
scanf("%d,%d;%d,%d;%d,%d",&a,&a1,&b,&b1,&c,&c1);

L=sqrt((a-b)*(a-b)+(a1-b1)*(a1-b1));

if(L<(L1=sqrt((a-c)*(a-c)+(a1-c1)*(a1-c1))))
{
L=L1+L;L1=L-L1;L=L-L1;//L exchange with L1
}

if(L<(L2=sqrt((b-c)*(b-c)+(b1-c1)*(b1-c1))))
{
L=L2+L;L2=L-L2;L=L-L2;//L exchange with L2
}

H=sqrt(L1*L1-(L*L+L1*L1-L2*L2)*(L*L+L1*L1-L2*L2)/(2*L*2*L));
area=L*H/2;
printf("the area of this triangle is %f\n",area);
}