您的位置:首页 > 其它

1132 -- 三角形面积

2015-08-31 16:50 330 查看
三角形面积
Time Limit:2000MS Memory Limit:65536K

Total Submit:968 Accepted:254
Description
给出三角形的三个边长为a,b,c,根据海伦公式来计算三角形的面积:

s=(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c));

Input
输入数据只有一组,即为三角形的三个边长a,b,c(100>a,b,c>0且均为整数)。

Output
输出三角形的面积,两位小数。如果不是一个三角形,则输出错误提示信息:"Input error!"。

注意输出没有引号。

Sample Input
3 4 5

Sample Output
6.00

Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1132 {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split();
double[] a = new double[3];
for (int i = 0; i < 3; i++)
a[i] = double.Parse(s[i]);
Array.Sort(a);
if (a[2] - a[0] >= a[1])
Console.WriteLine("Input error!");
else {
double b = (a[0] + a[1] + a[2]) / 2;
double c = Math.Sqrt(b * (b - a[0]) * (b - a[1]) * (b - a[2]));
Console.WriteLine(c.ToString("0.00"));
}
//Console.ReadLine();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: