# C Program to determine the type and Area of a Triangle

The following is a C Program to determine the type and Area of a Triangle:

Expected Output:

1st run:

2nd run:

## How it works

The above program uses two theorems:

• Triangle Inequality Theorem
• Heron’s Formula

### Triangle Inequality Theorem

The Triangle Inequality Theorem states that the sum of two sides of a triangle must be greater than the third side. Let a, b c be the three sides of the triangle then according to Triangle Inequality theorem:

We can also use Triangle Inequality theorem to determine whether the given three line segments can be used to construct a triangle or not.

In order for three line segments to form the sides of a triangle, all the three conditions must be satisfied.

If any one of the condition fails then the given line segments can’t be used to construct a triangle. For example:

Example 1: Can we construct a triangle using the following lengths: 7, 3, 2?

The second condition is false. Hence, lengths 7,3 and 2 can’t construct a triangle.

Example 2: Can we construct a triangle using the following lengths: 3, 4, 5?

All the three conditions are true. Hence, lengths 3, 4, 5 can be used to construct a triangle.

## Heron’s Formula

Heron’s Formula allows us to find the area of the triangle using the length of the three sides. $Area=\sqrt{s(s-a)(s-b)(s-c)}$

where s is called the semi perimeter of the triangle and is calculated as follows: $s=\frac{a+b+c}{2}$