C语言例题:计算三角形面积

题目:输入三角形的三边长,计算其面积。


INPUT

  • 输入三角形的三边长a,b,c

OUTPUT

  • 输出三角形的面积,保留两位小数

Sample Input

3 4 5

Sample Output

6.00


参考程序:

#include "stdio.h"
#include "math.h"
int main()
{
	float a, b, c;
	float s;
	float p;
	scanf("%f", &a);
	scanf("%f", &b);
	scanf("%f", &c);

	p = (a + b + c) / 2;
	s = sqrt(p*(p - a)*(p - b)*(p - c));	//海伦公式
	printf("%.2f", s);
}

你可能感兴趣的:(C语言例题整理)