logo image

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 );



Enter the base of triangle:
Enter the height of triangle:
Area of triangle is: 275