【题目来源】
https://www.luogu.com.cn/problem/P5708
【题目描述】
一个三角形的三边长分别是 a, b, c,请利用海伦公式计算三角形的面积。
计算结果四舍五入,精确到 1 位小数。
【输入格式】
第一行输入三个实数 a, b, c,以空格隔开。
【输出格式】
输出一个实数,表示三角形面积。精确到小数点后 1 位。
【输入样例】
3 4 5
【输出样例】
6.0
【说明/提示】
数据保证能构成三角形,0≤a, b, c≤1000,每个边长输入时不超过 2 位小数。
【Python代码】
from math import sqrt
a,b,c=map(float,input().split())
p=0.5*(a+b+c)
ans=sqrt(p*(p-a)*(p-b)*(p-c))
print("{0:.1f}".format(ans))
【C++代码】
#include<bits/stdc++.h>
using namespace std;double a,b,c;
double p,ans;
int main() {scanf("%lf %lf %lf",&a,&b,&c); //cin>>a>>b>>c;p=0.5*(a+b+c);ans=sqrt(p*(p-a)*(p-b)*(p-c)); //sqrt return doubleprintf("%.1lf",ans);return 0;
}/*
in:3 4 5
out:6.0
*/
【参考文献】
https://blog.csdn.net/m0_72538340/article/details/131012294
https://blog.csdn.net/m0_72538340/article/details/131023894
https://blog.csdn.net/hnjzsyjyj/article/details/134690871