C++ Chapters

C++ Program to Calculate the Area of a Triangle

Structure of C++ Programs - Overview
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int A, B, C, S, Area;
    
    cout << "Enter Length of Triangle's three sides : ";
    cin >> A;
    cin >> B;
    cin >> C;
    
    S = (A + B + C) / 2;
    Area = sqrt(S * (S - A) * (S - B) * (S - C));
    
    cout << "\n\nArea of Triangle is : " << Area;
    
    return 0;
}

Output :
Enter Length of Triangle's three sides : 10
20
20

Area of Triangle is : 96

Description :

Area of Trangle can be calculated as
s x (s-a) x (s-b) x (s-c)

Where s = half the perimeter (a+b+c)/2


Leave a comment
Recent Comments
No Comments