Table of Contents
The program computes the area of triangle once he user enters input values for the triangle. The inputs for the triangle are the length of base and height of the triangle.
Problem Definition
This program needs two critical information about a triangle -length of base and the height of the triangle. The base of the triangle is the longer side and one endpoint of the height divides the base. See the figure below.

Now, the formula to find the area is as follows.
\Large \begin{aligned} & Area = 1/2 \cdot (Base) \cdot (Height) \\\\
&Area = 1/2 \cdot b \cdot h\end{aligned}Flowchart- Area of a Triangle

Program Codes – Area of Triangle
C
C++
Java
Python
/* Area of Triangle */
#include < stdio.h >
#include < stdlib.h >
main()
{
float base, height, area, i;
printf("Enter Base of the Triangle:");
scanf("%f", & base);
printf("Enter Height of the Triangle:");
scanf("%f",& height);
area = (base / 2) * height;
for (i = 0; i < 35; i++)
printf("_"); printf("\n\n");
printf("Area of Triangle: %f\n", area);
for (i = 0; i < 35; i++)
printf("_"); printf("\n\n");
system("PAUSE");
return 0;
}#include <iostream>
using namespace std;
int main()
{
float base, height, area;
cout << "Enter Base of the Triangle: ";
cin >> base;
cout << "Enter Height of the Triangle: ";
cin >> height;
area = (base * height) / 2;
cout << "\n-----------------------------------\n";
cout << "Area of Triangle = " << area << endl;
cout << "-----------------------------------\n";
return 0;
}import java.util.Scanner;
class AreaOfTriangle
{
public static void main(String args[])
{
float base, height, area;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Base of the Triangle: ");
base = sc.nextFloat();
System.out.print("Enter Height of the Triangle: ");
height = sc.nextFloat();
area = (base * height) / 2;
System.out.println("\n-----------------------------------");
System.out.println("Area of Triangle = " + area);
System.out.println("-----------------------------------");
}
}base = float(input("Enter Base of the Triangle: "))
height = float(input("Enter Height of the Triangle: "))
area = (base * height) / 2
print("\n-----------------------------------")
print(f"Area of Triangle = {area}")
print("-----------------------------------")Output
The output of the above program is given below. When you enter the required input values – Base and Height of the triangle. The program computes the area and display it on the console.
Enter Base of the Triangle:20
Enter Height of the Triangle:12
_____________________________________
Area of Triangle: 120.000000
_____________________________________