-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlianxi05.html
More file actions
33 lines (31 loc) · 1010 Bytes
/
lianxi05.html
File metadata and controls
33 lines (31 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
/**
* 5、求三角形的面积和周长
* 输入三角形的三条边的值a, b, c,如果能构成一个三角形,输出面积area+最长边上的高的平方;
* 否则,输出“不能组成三角形”。
* 在一个三角形中,任意两边之和大于第三边。
* 三角形的面积计算公式:area*area = s(s-a)(s-b)(s-c)
* 其中:s = (a+b+c)/2
* 输出要求:精确到小数点后2位
*/
function five(a, b, c) {
var sideArray = new Array(a, b, c);
sideArray.sort();
if (sideArray[0] + sideArray[1] > sideArray[2]) {
var s = (a + b + c) / 2;
var area2 = s * (s - a) * (s - b) * (s - c);
console.info((Math.sqrt(area2) + 4 * area2 / (sideArray[2] * sideArray[2])).toFixed(2));
} else {
console.info("Con't be a triangle!");
}
}
five(4, 1, 4);
</script>
</body>
</html>