C语言输入三角形边长 输出三角形面积
时间: 2023-05-10 14:55:25 浏览: 92
可以使用海伦公式来计算三角形的面积,公式为:S = sqrt(p * (p - a) * (p - b) * (p - c)),其中p为半周长,即p = (a + b + c) / 2,a、b、c为三角形的三条边长。以下是C语言的代码实现:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, p, s;
printf("请输入三角形的三条边长:\n");
scanf("%f%f%f", &a, &b, &c);
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
printf("三角形的面积为:%f\n", s);
return 0;
}
相关问题
C语言用户输入三角形三条边长,输出面积
下面是用C语言编写的计算三角形面积的程序。
```c
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c, s, area;
printf("请输入三角形的三条边长:\n");
scanf("%f%f%f", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("三角形的面积为:%f\n", area);
return 0;
}
```
程序中使用了数学库中的sqrt函数来计算平方根。用户需要输入三角形的三条边长,程序会计算出三角形的半周长s,然后根据海伦公式计算出三角形的面积并输出。
C语言已知三角形边长求三角形周长
以下是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) {
float perimeter = a + b + c;
printf("三角形的周长为:%.2f\n", perimeter);
} else {
printf("这些边长不能构成一个有效的三角形\n");
}
return 0;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)