JavaScript 查找矩形的面积和周长
矩形是平面上的一个平的图形,它有四条边和四个等角,每个角都是90度。在矩形中,四条边的长度不相等,但是互相对立的两条边的长度相等。矩形的两条对角线长度相等。

示例:
Input: 4 5
Output: Area = 20
Perimeter = 18
Input: 2 3
Output: Area = 6
Perimeter = 10
公式:
Area of rectangle: a*b
Perimeter of rectangle: 2*(a + b)
示例: 下面是一个示例,将说明上述公式:
JavaScript
<script>
// Function to Find the Area of Triangle
function areaRectangle(a, b) {
let area = a * b;
return area;
}
// Function to Find the Parameter of Triangle
function perimeterRectangle(a, b) {
let perimeter = 2 * (a + b);
return perimeter;
}
// Driver program
let a = 5;
let b = 6;
console.log("Area = " + areaRectangle(a, b));
console.log("Perimeter = " + perimeterRectangle(a, b));
</script>
输出:
Area = 30
Perimeter = 22
时间复杂度 : O(1),因为它执行的是常数时间的操作
辅助空间: O(1)
极客教程