Area of the triangle

Area of the triangle is given by the formula A = hb/2 , where b is base and h is height of the triangle.

Required knowledge & Programming Software

Arithmetic operator
Variables and expression
Data types
Basic input/output
Dev C++ /Turbo C++

Logic to find area of triangle

Steps for finding area of a triangle were discussed below:
Input base of the triangle say “b” and store in some variable say “base”.
Input height of the triangle say “h” and store in some variable say “height”.
Use the formula for calculating area of the triangle, area = (base * height) / 2
Print the resultant area of the triangle.

Program to find area of triangle

#include <stdio.h>
main()
{
float base, height, area;
/* Input base and height of triangle */
printf("Enter base of the triangle: ");
scanf("%f", &base);
printf("Enter height of the triangle: ");
scanf("%f", &height);
/* Calculate area of triangle */
area = (base * height) / 2;
/* Print the resultant area */
printf("Area of the triangle = %.2f sq. units", area);
}


Example

INPUT
Enter the base of the triangle: 5
Enter height of the triangle: 6
OUTPUT
Area of the triangle = 15 sq. units

If you have any doubt for calculating area of triangle  drop a comment below and let us know our support team will get back to you as soon as possible. If you liked our content please share and subscribe to our newsletter.