用c语言完成题目内容: 输入三角型的三条边,判断三角形的形状。假设输入的三边边长均>0。 输入格式: 三角型的3条边的长度(int型)。 输出格式: 等边三角形:equilateral triangle 等腰三角形:isoceles triangle 不构成三角形:non-triangle 一般三角形:triangle 输入样例: 2 2 2 输出样例: equilateral triangle.
时间: 2023-06-19 14:05:04 浏览: 84
以下是用C语言实现的代码:
```c
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a + b <= c || a + c <= b || b + c <= a) {
printf("non-triangle");
}
else if (a == b && b == c) {
printf("equilateral triangle");
}
else if (a == b || a == c || b == c) {
printf("isoceles triangle");
}
else {
printf("triangle");
}
return 0;
}
```
首先读入三角形的三条边的长度,然后根据三边的关系判断三角形的形状,最后输出对应的字符串。需要注意的是,判断三角形是否存在的条件是任意两条边之和大于第三条边,如果不满足这个条件,就不能构成三角形。
相关问题
用C语言写出输入三角形的三条边判断是否构成三角形,若能指出是什么三角形
好的,以下是C语言实现的程序:
```c
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边长:\n");
scanf("%f%f%f", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a)
{
if (a == b && b == c)
{
printf("这是一个等边三角形\n");
}
else if (a == b || a == c || b == c)
{
printf("这是一个等腰三角形\n");
}
else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
{
printf("这是一个直角三角形\n");
}
else
{
printf("这是一个普通三角形\n");
}
}
else
{
printf("这三条边无法构成三角形\n");
}
return 0;
}
```
程序首先要求输入三角形的三条边长,然后根据三角形成立的条件判断它们是否能构成三角形。如果能构成三角形,则再根据边长的关系判断它是等边三角形、等腰三角形、直角三角形还是普通三角形,最后输出判断结果。如果不能构成三角形,则直接输出无法构成三角形的信息。
注意:程序中的平方计算要使用 `*` 符号,而不是 `^` 符号。同时,为了避免精度问题,我们可以使用 `math.h` 头文件中的 `pow()` 函数来进行平方计算。
c语言输入三条边判断三角形
好的,针对你的问题,可以使用以下代码来实现:
```c
#include <stdio.h>
int main() {
float a, b, c;
printf("请输入三角形的三条边长:\n");
scanf("%f %f %f", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
printf("这是一个三角形。\n");
if (a == b && b == c) {
printf("这是一个等边三角形。\n");
} else if (a == b || a == c || b == c) {
printf("这是一个等腰三角形。\n");
} else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
printf("这是一个直角三角形。\n");
} else {
printf("这是一个普通三角形。\n");
}
} else {
printf("这不是一个三角形。\n");
}
return 0;
}
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.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)
![](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)