C# program to calculate triangle area
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
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine("Enter the base of triangle:");
double triangleBase = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the height of triangle:");
double triangleHeight = Convert.ToDouble(Console.ReadLine());
double areaOfTriangle = (triangleBase * triangleHeight) / 2;
Console.WriteLine("Area of triangle is: " + areaOfTriangle );
}
}
Output:
Enter the base of triangle:
22
Enter the height of triangle:
25
Area of triangle is: 275