给定平面上任意三个点的坐标(x 1 ,y 1 )、(x 2 ,y 2 )、(x 3 ,y 3 ),检验它们能否构成三角形。 输入格式: 输入在一行中顺序给出六个[−100,100]范围内的数字,即三个点的坐标x 1 、y 1 、x 2 、y 2 、x 3 、y 3 。 输出格式: 若这3个点不能构成三角形,则在一行中输出“impossible”;若可以,则在一行中输出该三角形的周长和面积,格式为“l = 周
时间: 2023-04-13 22:02:34 浏览: 172
长, s = 面积”,结果保留两位小数。若输出的周长或面积为整数,则在小数点后保留位。
思路:根据三角形的性质,任意两边之和大于第三边,任意两边之差小于第三边。因此,我们可以计算出三条边的长度,然后判断是否符合三角形的条件。如果符合条件,则可以计算出周长和面积。
代码如下:
相关问题
用c语言写给定平面上任意三个点的坐标(x 1 ,y 1 )、(x 2 ,y 2 )、(x 3 ,y 3 ),检验它们能否构成三角形。
```c
#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2, x3, y3;
float side1, side2, side3;
printf("Enter the coordinates of three points (x1,y1), (x2,y2), (x3,y3): ");
scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
side1 = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
side2 = sqrt(pow((x3 - x2), 2) + pow((y3 - y2), 2));
side3 = sqrt(pow((x1 - x3), 2) + pow((y1 - y3), 2));
if (side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1)
{
printf("The given points form a triangle.\n");
}
else
{
printf("The given points do not form a triangle.\n");
}
return 0;
}
```
用C语言编写下列程序,给定平面上任意三个点的坐标(x 1 ,y 1 )、(x 2 ,y 2 )、(x 3 ,y 3 ),检验它们能否构成三角形
以下是用C语言编写的程序,可以检验给定的三个点能否构成三角形:
```
#include <stdio.h>
int main() {
float x1, y1, x2, y2, x3, y3;
printf("请输入三个点的坐标:\n");
scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
float a = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); // 计算三条边的长度
float b = sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2));
float c = sqrt((x1-x3)*(x1-x3) + (y1-y3)*(y1-y3));
if (a+b>c && a+c>b && b+c>a) { // 判断是否构成三角形
printf("这三个点能构成三角形!\n");
} else {
printf("这三个点不能构成三角形!\n");
}
return 0;
}
```
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)