c语言函数判断三角形类型
时间: 2023-12-21 21:29:01 浏览: 73
以下是一个判断三角形类型的C语言函数的例子:
```c
#include <stdio.h>
#include <math.h>
void triangleType(float a, float b, float c) {
if (a + b > c && a + c > b && b + c > a) { // 判断是否能构成三角形
if (a == b && b == c) { // 判断是否为等边三角形
printf("Equilateral triangle\n");
} else if (a == b || a == c || b == c) { // 判断是否为等腰三角形
printf("Isosceles triangle\n");
} else { // 否则为普通三角形
printf("Ordinary triangle\n");
}
float p = (a + b + c) / 2; // 计算半周长
float area = sqrt(p * (p - a) * (p - b) * (p - c)); // 计算面积
printf("Area: %f\n", area);
} else {
printf("Cannot form a triangle\n");
}
}
int main() {
float a, b, c;
printf("Enter the three sides of the triangle: ");
scanf("%f %f %f", &a, &b, &c);
triangleType(a, b, c);
return 0;
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)