游客 Signup | Login
中文 | En

3437 - 求三角形的面积

已知三角形的三边长为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> 

Input

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

Output

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

Examples

Input

3 4 5
3 3 5

Output

6.00
4.15

Solution 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;
}

Solution 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;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题