• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 22, 2022 |480 Views
C++ program to find the perimeter and area of triangle
Description
Discussion

In this video, we will write a C++ program to find the perimeter and area of a triangle. Triangles are three-sided collective polygons formed by the intersection of three lines. It consists of three sides, three angles, and three vertices.

Area of a triangle: 

The area of a triangle is defined as the total space occupied by the three sides of a triangle in a 2- dimensional plane.
Formula:
A = 1/2 × b × h

The perimeter of the triangle: 

To calculate the perimeter of a triangle, we just add the length of its all sides. Suppose, if a triangle has sides x, y, and z, also the perimeter of that triangle will be:
P = (x+y+z)

Example:
Input h and b : 3 4
Output Area = 6
Perimeter = 10

Approach:

Step 1: Initialize six variables: a,b, c,s,area and perimeter.
Step 2: Take input of a,b, and c from the user.
Step 3: Calculate the value of s.
Step 4: Calculate the area and perimeter of the triable using the formula and store the value in respective variables.
Step 5: Print the area and perimeter of the triangle.

Read More