C++ Program to Calculate Area of Triangle

In this C++ Programming tutorial we will see a Program to Calculate Area of Triangle in C++ Programming language. We will accept the height and base values from user and apply the formula of Area of triangle : (1/2)*Base*Height.

Program to Calculate Area of Triangle in C++
#include <iostream>
using namespace std;

int main() {
    int height, base;
    float ans;    //ans may come in fractions
    cout<<"Enter height and base : ";
    cin>>height>>base;
    ans= (0.5)*height*base;    //area of triangle formula

    cout<<"Area of triangle is : "<<ans;
	return 0;
}
Output
Enter height and base : 6 8
Area of triangle is : 24

Leave a Reply

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