GET EDUCATE

Contents
Basics of C Programming

⯈Basic C Programs

Algorithm and Flowchart to calculate area of triangle

This problem can be solved either by considering the input as three sides of the triangle, or the input as base and height of the triangle. 

Let us solve this by considering three sides of a triangle.

Input: Given three sides of the triangle. Let the three sides of triangle be ‘a’, ‘b’ and ‘c’. Whenever we write algorithm or program, we always start from reading the input. 

Reading input: Read three sides of triangle as ‘a’, b’ and ‘c’.

Formula: area = √( s *(s-a) * (s-b) * (s-c) ), where s is the semi perimeter. 

s = (a+b+c)/2

After we calculate the area, we display area.

The algorithm for area of triangle is as follows:

Algorithm:

Name of Algorithm: To compute area of triangle given three sides.

Step 1: Start

Step 2: Read three sides as ‘a’, ‘b’ and ‘c’

Step 3: s = (a+b+c)/2 [Computing semi perimeter]

Step 4: area = √(s *(s-a) * (s-b) * (s-c))

Step 5: Display area

Step 6: stop.

Note: All that we calculate may/may not be in the output.

Here we have calculated semi perimeter (s) but didn’t output it.

Flowchart:

flowchart area of triangle given three sides

Tracing:

In step two we read the three sides of triangle,

Let a = 3, b = 4 and c = 5

In step three, we compute s = (3+4+5)/2 = 6

In step 4, we compute area as,

area = √(s *(s-a) * (s-b) * (s-c))

        = √(6*(6-3)*(6-4)*(6-5)

       = 6 sq units

Scroll to Top