用c语言判断三点是否构成三角形。并计算周长和面积
时间: 2023-04-10 15:00:29 浏览: 128
判定三点是否可以构成三角形.cpp
可以回答这个问题。以下是用 C 语言判断三点是否构成三角形,并计算周长和面积的代码:
#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2, x3, y3;
float a, b, c, s, area;
printf("Enter the coordinates of three points:\n");
scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
b = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));
c = sqrt(pow(x1 - x3, 2) + pow(y1 - y3, 2));
if (a + b > c && b + c > a && c + a > b)
{
printf("The three points form a triangle.\n");
printf("Perimeter = %.2f\n", a + b + c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area = %.2f\n", area);
}
else
{
printf("The three points do not form a triangle.\n");
}
return 0;
}
阅读全文