logo image

C++ program to calculate triangle area

Views: 17

Following program shows you how to calculate triangle area. This program gets triangle base and height from user and calculates area and prints it using following formula Area = base X height / 2

#include <iostream>
#include <math.h>

int main() {
	float triangleBase;
	float triangleHeight;

	std::cout << "Enter the base of triangle:";
	std::cin >> triangleBase;

	std::cout << "Enter the height of triangle:";
	std::cin >> triangleHeight;

	float areaOfTriangle = (triangleBase * triangleHeight) / 2;

	std::cout << "Area of triangle is: " << areaOfTriangle;
}

Output:

Enter the base of triangle: 22
Enter the height of triangle: 33
Area of triangle is: 363