From 57684ccd224e73e68179f882f71cd1d8241ea4e9 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 8 Nov 2024 22:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=A2=9D=E5=A4=96=E7=BB=83=E4=B9=A0?= =?UTF-8?q?=E3=80=91=E9=80=89=E6=8B=A9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 【额外练习】选择结构/7-48 选择-三角形面积2.c | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 【额外练习】选择结构/7-48 选择-三角形面积2.c diff --git a/【额外练习】选择结构/7-48 选择-三角形面积2.c b/【额外练习】选择结构/7-48 选择-三角形面积2.c new file mode 100644 index 0000000..2965e06 --- /dev/null +++ b/【额外练习】选择结构/7-48 选择-三角形面积2.c @@ -0,0 +1,24 @@ +#include +#include + +int main() { + int x1, y1, x2, y2, x3, y3; + double a, b, c, s, area; + + scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3); + + a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); + b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)); + c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)); + + if (a + b > c && a + c > b && b + c > a) { + s = (a + b + c) / 2; + area = sqrt(s * (s - a) * (s - b) * (s - c)); + + printf("%.1f %.1f\n", a + b + c, area); + } else { + printf("no triangle!\n"); + } + + return 0; +}