用c语言编写 输入三角形的三边长abc分别为3.1 4.2 5.3 求三角形的面积 已知三角形的三边长abc 其中s=a+b+c÷2则三角形的面积公式为
时间: 2023-09-23 19:07:22 浏览: 207
根据海伦公式,三角形的面积公式为:
s = (a + b + c) / 2
area = sqrt(s * (s - a) * (s - b) * (s - c))
因此,可以用下面的C代码来计算三角形的面积:
```c
#include <stdio.h>
#include <math.h>
int main() {
double a = 3.1;
double b = 4.2;
double c = 5.3;
double s = (a + b + c) / 2;
double area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("The area of the triangle is: %lf\n", area);
return 0;
}
```
输出结果为:The area of the triangle is: 6.349516。
相关问题
用C语言编写输入三角形三边长,求三角形面积的程序。
好的,以下是用 C 语言编写输入三角形三边长,求三角形面积的程序:
```c
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, p, area;
printf("请输入三角形的三条边长:\n");
scanf("%lf %lf %lf", &a, &b, &c);
p = (a + b + c) / 2; // 计算半周长
area = sqrt(p * (p - a) * (p - b) * (p - c)); // 计算面积
printf("三角形面积为:%lf\n", area);
return 0;
}
```
以上是用 C 语言编写输入三角形三边长,求三角形面积的程序。如有疑问,可以继续提问。
用c语言编程已知三角形三边的长,求该三角形的面积;
可以使用海伦公式来计算三角形的面积,公式为:S = sqrt(p * (p - a) * (p - b) * (p - c)),其中a、b、c为三角形的三条边长,p为半周长,即p = (a + b + c) / 2。在C语言中,可以使用sqrt函数来计算平方根,代码如下:
#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 ;
}
阅读全文
相关推荐
![](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)