首页 > 代码库 > (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)海伦公式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。