求三角形面积
Problem Description
已知三角形的边长a、b和c,求其面积。
Input
输入三边a、b、c。
Output
输出面积,保留3位小数。
Example Input
1 2 2.5
Example Output
0.950
Hint
海伦公式求三角形面积。如果三角形的三边为a, b, c且p=(a+b+c)/2,则三角形面积为(p*(p-a) * (p - b) * (p -c))的平方根。
代码:
#include <stdio.h>
#include <math.h>
double f(double a, double b, double c);
int main()
{
double a, b, c, s;
scanf("%lf%lf%lf", &a, &b, &c);
s = f(a, b, c);
printf("%.3lf\n", s);
return 0;
}
double f(double a, double b, double c)
{
double p, s;
p = (a + b +c) / 2.0;
s = sqrt((p * (p - a)*(p - b)*(p - c)));
return s;
}