3437 - 求三角形的面积

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

已知三角形的三边长为abc,计算三角形面积的公式为:


<span style="font-size:14px;">&nbsp; &nbsp; &nbsp;</span><img src="http://tk.hustoj.com:80/attached/image/20141122/20141122234845_99579.png" alt="" /> 

<span style="font-size:14px;">要求编写程序,从键盘输入</span><i><span style="font-size:14px;">a</span></i><span style="font-size:14px;">,</span><i><span style="font-size:14px;">b</span></i><span style="font-size:14px;">,</span><i><span style="font-size:14px;">c</span></i><span style="font-size:14px;">的值,计算并输出三角形的面积。</span><span></span> 

题目输入

输入有多组样例,输入a,b,c的值。(0<a,b,c<100)a,b,c三个数都为整型

题目输出

输出三角形的面积。结果保留两位小数

输入/输出样例

输入格式

3 4 5
3 3 5

输出格式

6.00
4.15

C语言解答

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

C++解答

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{
  //  freopen("in","r",stdin);
 //   freopen("out","w",stdout);

    float a,b,c,s,area;

    while(scanf("%f%f%f",&a,&b,&c)!=EOF)
    {
       s=1.0/2*(a+b+c);
       area=sqrt(s*(s-a)*(s-b)*(s-c));
       printf("%.2f\n",area);
    }
  return 0;
}