mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 09:38:42 +00:00
【额外练习】选择结构
This commit is contained in:
parent
3040899e0f
commit
57684ccd22
24
【额外练习】选择结构/7-48 选择-三角形面积2.c
Normal file
24
【额外练习】选择结构/7-48 选择-三角形面积2.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user