首页 > 代码库 > (c语法百题34)海伦公式

(c语法百题34)海伦公式

知识点:

数学函数sqrt()的运用

头文件math.h记得加上

了解海伦公式

 

内容: 已知3边长,求三角形面积

 

输入说明:

一行 三个数

 

输出说明:

一行一个数(保留2位小数)或者是 Data Error!(不能构成三角形)

输入样例:

1 2 3

 

输出样例 :

Data Error!

 

#include <stdio.h>#include <math.h>int main(){ float a,b,c,p,s; scanf("%f%f%f",&a,&b,&c); p=(a+b+c)/2; if(a+b>c&&a+c>b&&b+c>a) {  s=sqrt(p*(p-a)*(p-b)*(p-c));  printf("%.2f\n",s); } else  {  printf("Data Error!\n"); } return 0;}

 

(c语法百题34)海伦公式