C Program to Find Area of Triangle

In this example, We will understand how to find Area of Triangle.

1. Area of Right Angled Triangle

We know the formula for area of right angled triangle is

area = (p * b)/2

where p = perpendicular and b= base

#include<stdio.h>
void main()
{
    float p,b,area;
    p=10.2;
    b=15.6;
    area=(p*b)/2;
    printf("area of Triangle = %f",area);
}

Output

area of Trinagle = 79.56

2. Area of non equilateral Triangle

If the triangle is non equilateral means all side of triangle is different size. Then The formula for triangle will be

#include<stdio.h>
void main()
{
    float a,b,c,temp,area;
    a=10;
    b=15;
    c=20;
    temp = (s*(s-a)*(s-b)*(s-c));
    area = pow(temp,0.5);
    printf("Area of the Triangle = %.2f",area);
}

Output

Area of the Triangle = 72.62

Explanation

In this example, a,b,c variables are used to store values of three side of triangle. Where as temp is used to store temporary value and then we have to find under root of temp. For that, we know under root is equals to power of 0.5. so we used a built in function pow().

Share in a Single Click

Leave a Reply

Your email address will not be published. Required fields are marked *