C# program to calculate trapezoid area

Views: 264   

Following program shows you how to calculate trapezoid area.
This program gets trapezoid base and height from user and calculates area and prints it using following formula
Area = (base1 + base2) X height /2

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine("Please enter base1 of trapezoid:");
    double trapezoidBase1 = Convert.ToDouble(Console.ReadLine());

    Console.WriteLine("Please enter base2 of trapezoid:");
    double trapezoidBase2  = Convert.ToDouble(Console.ReadLine());

    Console.WriteLine("Please enter height  of trapezoid:");
    double trapezoidHeight  = Convert.ToDouble(Console.ReadLine());

    double areaOfTrapezoid = (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2;
    Console.WriteLine("Area of trapezoid is: " + areaOfTrapezoid);



Please enter base1 of trapezoid:
Please enter base2 of trapezoid:
Please enter height  of trapezoid:
Area of trapezoid is: 252
On By