The area of a triangle is a fundamental geometric concept in C language we can compute the area of a triangle by using a simple mathematical formula. In this article, we will write a program to find the Area of a triangle.

## Table of Contents

## Area of Triangle Formula

The area of a triangle can be calculated by using the formula-

**Area = 1/2* base * height**

Here the base represents the length of the triangle’s base and height is the perpendicular distance from the base to the opposite vertix.

## C Program for Calculating Area of Triangle

```
#include <stdio.h>
void main()
{
float base, height, area;
printf("Enter the base of triangle ");
scanf("%f", &base);
printf("Enter the heigth of triangle ");
scanf("%f", &height);
if (base > 0 && height > 0)
{
area = 0.5 * base * height; // 1/2 = 0.5
printf("The area of triangle = %f", area);
}
else
{
printf("Invalid input- Both base and height must be possitive");
}
}
```

### Output

The above C program asks the user to enter the base and height of the triangle. after that, the program checks whether both base and height are positive values before proceeding with the area calculation. if the input is valid, the C program calculates the area of a triangle and prints the result.

*Happy Coding*

## 1 thought on “Area of Triangle in C”