C program to find area of triangle

devquora
devquora

Posted On: Jan 27, 2023

C program to find area of triangle

 

Overview:

In general, the term “area” is defined as the region occupied inside the boundary of a flat object or figure. Before, Starting this article First of all, I want to introduce you with Geometric Shape triangle. Then I will explain What do you mean by area of a triangle and Heron’s Formula? Moreover, I will demonstrate how to find area of a triangle? Furthermore, I will write logic and c program to find area of triangle with output. After all, I will explain the resultant output.

Table of contents:

  1. What is a Triangle?
  2. What are the properties of the Triangle?
  3. What are the types of Triangle?
  4. What is Right Angled Triangle?
  5. What is Obtuse-angled Triangle?
  6. What is Acute angled Triangle?
  7. What is Equilateral Triangle?
  8. What is Isosceles Triangle?
  9. What is Scalene Triangle?
  10. What do you mean by the area of a triangle?
  11. Demonstration how to find area of a triangle.
  12. Define Heron’s Formula.
  13. How to calculate the area of a Right Angled Triangle?
  14. How to calculate the area of a Obtuse-angled Triangle?
  15. How to calculate the area of a Acute angled Triangle?
  16. How to calculate the area of a Equilateral Triangle?
  17. How to calculate the area of a Isosceles Triangle?
  18. How to calculate the area of a Scalene Triangle?
  19. Main Logic to find the area of a triangle.
  20. C program to find area of triangle
  21. Conclusion

What is a Triangle?

A triangle is a three-sided polygon that consists of three edges and three vertices. If ABC is a triangle, then it is denoted as ∆ABC, where A, B and C are the vertices of the triangle and AB, BC, CA are the edges of the triangle. A triangle is a two-dimensional Geometric shape.

What are the properties of the Triangle?

The properties of the triangle are as follows:

  1. The sum of all the angles of a triangle(of all types) is equal to 180°.
  2. The sum of the length of the two sides of a triangle is greater than the length of the third side.
  3. In the same way, the difference between the two sides of a triangle is less than the length of the third side.
  4. The side opposite the greater angle is the longest side of all the three sides of a triangle.
  5. The exterior angle of a triangle is always equal to the sum of the interior opposite angles. This property of a triangle is called an exterior angle property.
  6. Two triangles are said to be similar if their corresponding angles of both triangles are congruent and lengths of their sides are proportional.
  7. Area of a triangle = ½ × Base × Height
  8. The perimeter of a triangle = sum of all its three sides

What are the types of Triangle?

Types of Triangle

Triangles can be broadly classified into two types, which are:

  1. Triangles based on the lengths of their sides
  2. Triangles based on their interior angles
  3. On the basis of the lengths of their sides, triangles are classified in three categories:
    1. Scalene Triangle
    2. Isosceles Triangle
    3. Equilateral Triangle
    On the basis of their interior angles, triangles are classified in three categories:
    1. Right Triangle
    2. Obtuse Triangle
    3. Acute Triangle

A right-angled triangle, also called a right triangle has one angle at 90° and the other two acute angles sums to 90°. Therefore, the height of the triangle will be the length of the perpendicular side.

What is Obtuse-angled Triangle?

Obtuse triangles are those in which one of the three interior angles has a measure greater than 90 degrees. In other words, if one of the angles in a triangle is an obtuse angle, then the triangle is called an obtuse-angled triangle.

What is Acute angled Triangle?

An acute triangle is a triangle whose all three interior angles are acute. In other words, if all interior angles are less than 90 degrees, then it is an acute-angled triangle.

What is Equilateral Triangle?

An equilateral triangle is a triangle where all the sides are equal. The perpendicular drawn from the vertex of the triangle to the base divides the base into two equal parts.

What is Isosceles Triangle?

An isosceles triangle is one which has at least two sides of equal length. This property is equivalent to two angles of the triangle being equal.

What is Scalene Triangle?

A simple definition of a scalene triangle is “A Scalene triangle is a triangle with three different sides and angles. ” In other words, A Scalene triangle has three random(Unequal) sides/lengths and three random (Unequal) angles.

What do you mean by the area of a triangle?

The area of the triangle is the region enclosed by its perimeter or the three sides of the triangle. The standard unit for measurement of the area is meter2. In general area of the triangle is calculated by two ways as follows:

  • The Basic formula for the area of the triangle: A = ½ × Base × Height(Perpendicular distance).
  • The “Heron’s Formula” for the area of the triangle: √(s*(s-a)*(s-b)*(s-c));

Demonstration how to find area of a triangle:

Triangle Area

Define Heron’s Formula.

Heron’s formula includes two important steps as follows:

    • Step 1: Find the semi perimeter of a triangle by adding all the three sides of a triangle and dividing it by 2.
    • Step 2: apply the semi-perimeter of triangle value in the main formula called “Heron’s Formula” to find the area of a triangle.

The main formula called “Heron’s Formula” to find the area of a triangle is as follows:

√(s × (s-a) × (s-b) × (s-c));

The measurement unit of the area of a triangle is a square unit.

How to calculate the area of a Right Angled Triangle?

The Area of a Right Triangle is calculated by using following formula:

A = ½ × Base × Height(Perpendicular distance)

How to calculate the area of a Obtuse-angled Triangle?

The area of the obtuse-angled triangle is given by: Area = 1/2 × b × h where b is the base and h is the height of the triangle.

How to calculate the area of a Acute angled Triangle?

The area of acute angle triangle = (½) × b × h square units

How to calculate the area of a Equilateral Triangle?

The Area of an Equilateral Triangle is calculated by the formula:

A = (√3)/4 × side2

How to calculate the area of a Isosceles Triangle?

The general formula for the area of the triangle is equal to half the product of the base and height of the triangle.

The area of a scalene triangle is calculated by:

A =1/2 × b × h square units.

Where,

base 'b' is any side of the triangle

height ‘h’ is an altitude on that base

How to calculate the area of a Scalene Triangle?

The area of a scalene triangle is calculated by:

A =1\2 × b × h square units.

Where,

base 'b' is any side of the triangle

height ‘h’ is an altitude on that base

Main Logic to find the area of a triangle

  • Step 1: First of all declare 6 variables such as a, b,c for triangle sides, Perimeter P, semi perimeter s and Area.
  • Step 1: User will enter the three sides of the triangle a, b, c.
  • Step 2: Calculating the Perimeter of the Triangle using the formula P = a + b + c.
  • Step 3: Calculating the semi perimeter using the formula (a + b + c)/2 and store it into variable s.
  • Step 4: Calculating the Area of a triangle using Heron’s Formula: √(s × (s - a) × (s - b) × (s - c)); and store it into Area variable.
  • Step 4: Print the variable area.

C program to find area of triangle

/* C Program to find Area of a Triangle and Perimeter of a Triangle */

#include <stdio.h>
#include <math.h>

int main()
{
  float a, b, c, P, s, Area;
  
  printf("\nPlease! Enter First edge of the triangle: ");
  scanf("%f",&a);
  printf("\nPlease! Enter Second edge of the triangle: ");
  scanf("%f",&b);
  printf("\nPlease! Enter Third edge of the triangle: ");
  scanf("%f",&c);  
  P = a + b + c;
  s = (a + b + c)/2;
  Area = sqrt(s * (s - a) * (s - b) * (s - c));
   
  printf("\n Perimeter of the Triangle = %.2f\n", Perimeter);
  printf("\n Semi Perimeter of the Triangle = %.2f\n",s);
  printf("\n Area of the triangle = %.2f\n",Area);

  return 0;
}

The output of the Program:

Area of Triangle Output

Conclusion

In this Program, User will enter the three sides of the triangle a, b, c. Then, Calculating the Perimeter of the Triangle. Moreover, calculating the semi perimeter using the formula (a + b + c) / 2 and calculating the Area of a triangle using Heron’s Formula: √(s × (s - a) × (s - b) × (s - c)). After the successful execution of the program the final area of a triangle is shown on screen.

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..