1134 - C语言4.9
时间限制 : 1 秒
内存限制 : 32 MB
输入三角形的三边长,使用海伦公式计算三角形的面积。
题目输入
只有一行,用空格分开的三个浮点数,分别为三角形的三边长。输入保证三角形不会退化。
题目输出
输出三角形的面积,保留2位小数。
请注意行尾输出换行。
输入/输出样例
输入格式
3 4 6
输出格式
5.33
C语言解答
#include<stdio.h> #include<math.h> int main(){ double a,b,c,s,L; scanf("%lf %lf %lf",&a,&b,&c); s=(a+b+c)/2; L=sqrt(s*(s-a)*(s-b)*(s-c)); printf("%.2lf",L); return 0; }
C++解答
#include <stdio.h> #include <math.h> int main() { float a, b, c, s, area; scanf("%f %f %f", &a, &b, &c); s = (a + b + c) * 0.5; area = sqrt(s * (s - a) * (s - b) * (s - c)); printf("%.2f\n", area); return 0; }
Java解答
import java.util.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); double a,b,c; double p; double hl; a=cin.nextDouble(); b=cin.nextDouble(); c=cin.nextDouble(); p=(a+b+c)/2; hl=Math.sqrt(p*(p-a)*(p-b)*(p-c)); System.out.printf("%.2f",hl); } }
Python解答
from math import sqrt a,b,c = [float(x) for x in raw_input().split()] p = (a+b+c)/2 print "%.2f" %sqrt(p*(p-a)*(p-b)*(p-c))