Open In App

JavaScript program to find perimeter of a triangle

Last Updated : 04 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given the side (a, b, c) of a triangle and we have to find the perimeter of a triangle.

Perimeter: Perimeter of a triangle is the sum of the length of the side of a triangle.

Perimeter of a triangle

Where a, b, and c are lengths of sides of a triangle. The perimeter of a triangle can be simply evaluated using the following formula:

Perimeter = (a + b + c)

Examples:

Input : a = 2.0, b = 3.0, c = 5.0
Output : 10.0


Input : a = 5.0, b = 6.0, c = 7.0 
Output : 18.0

Example: Below is the implementation of above approach:

Javascript




<script>
  
    // JavaScript program to find the perimeter
    // of a triangle
    function findPerimeter(a, b, c) {
  
        // Formula for Perimeter of a triangle
        return (a + b + c);
    }
  
    // Driver Code
    let a = 2.0, b = 3.0, c = 5.0;
  
    console.log(findPerimeter(a, b, c));
</script>


Output:

10.0

Time Complexity: O(1).
Auxiliary Space: O(1).


Similar Reads

Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
Given the length of sides of an equilateral triangle, the task is to find the area and perimeter of Incircle of the given equilateral triangle. Examples: Input: side = 6 Output: Area = 9.4. Perimeter = 10.88 Input: side = 9 Output: Area = 21.21, Perimeter = 16.32 Properties of an Incircle are: The center of the Incircle is same as the center of the
4 min read
Find Perimeter of a triangle
Given side (a, b, c) of a triangle, we have to find the perimeter of a triangle. Perimeter : Perimeter of a triangle is the sum of the length of side of a triangle. where a, b, c are length of side of a triangle.Perimeter of a triangle can simply be evaluated using following formula : [Tex]perimeter = (a + b + c) [/Tex] Examples : Input : a = 2.0,
3 min read
Maximum Perimeter Triangle from array
Given an array of non-negative integers. Find out three elements from this array that form a triangle of the maximum perimeter.Examples: Input : {6, 1, 6, 5, 8, 4}Output : 20Input : {2, 20, 7, 55, 1, 33, 12, 4}Output : Triangle formation is not possible.Input: {33, 6, 20, 1, 8, 12, 5, 55, 4, 9}Output: 41 Recommended PracticeMaximum Perimeter of Tri
24 min read
JavaScript program to find Area and Perimeter of Rectangle
A rectangle is a flat figure in a plane. It has four sides and four equal angles of 90 degrees each. In a rectangle all four sides are not of equal length like a square, sides opposite to each other have equal length. Both diagonals of the rectangle have equal lengths. Examples: Input: 4 5 Output: Area = 20 Perimeter = 18 Input: 2 3 Output: Area =
1 min read
JavaScript Program to Find Perimeter of Square
Given the length of one side, our task is to find the perimeter of a square in JavaScript. The perimeter of a square is the total length of its four sides. It can be calculated by multiplying the length of one side by 4 and all its angles measure 90 degrees. Example: Formula for calculating Perimeter of Square is: 4*s Where, s is sides of a square
2 min read
JavaScript Program to Find Perimeter of Parallelogram
Given the length of one side, our task is to find the perimeter of a parallelogram in JavaScript. A parallelogram is a geometric shape having four sides and its opposite sides are parallel and equal in length, and its opposite angles are also equal. The perimeter of a parallelogram is the total length of its four sides. It can be calculated by addi
2 min read
Program to print a Hollow Triangle inside a Triangle
Given a number N(? 8), the task is to print a Hollow Triangle inside a Triangle pattern.Example: Input: N = 9 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Approach: Let i be the index for rows and j be the index for columns. Then: For sides of outer triangle: If the index of column(j) is equals to (N - i + 1) or (
7 min read
Program to find the Area and Perimeter of a Semicircle
Given the radius of the semicircle as r, the task is to find out the Area and Perimeter of that semicircle.Examples: Input: r = 10 Output: Area = 157.00, Perimeter = 31.4 Input: r = 25 Output: Area =981.250000, Perimeter = 78.500000 Approach: In mathematics, a semicircle is a one-dimensional locus of points that forms half of a circle. The area of
5 min read
Program to find the Perimeter of a Regular Polygon
Given the number of sides 'n' and the length of side 's' of a regular polygon, the task is to find out the Perimeter of this polygon. Examples: Input: n = 7, s = 10 Output: Perimeter : 70 Since the sides are 7, Hence the given polygon is Heptagon. Therefore. Perimeter = 7*10 = 70 Input: n = 5, s = 2.5 Output: Perimeter : 12.5 Since the sides are 5,
5 min read
Program to find all possible triangles having same Area and Perimeter
The task is to find all possible triangles having the same perimeter and area. Examples: The triangle having sides (6, 8, 10) have the same perimeter (= (6 + 8 + 10) = 24) and area (= 0.5 * 6 * 8 = 24). Approach: The idea is based on the observation from Heron's Formula. Below are the observations: Let the sides of the triangle be a, b, c.Perimeter
9 min read