logo image

Go language program to calculate trapezoid area

Views: 16

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

package main

import "fmt"

func main() {

  var trapezoidBase1 float64
  var trapezoidBase2 float64
  var trapezoidHeight float64
  var areaOfTrapezoid float64
  fmt.Println("Please enter base1 of trapezoid:")
  fmt.Scanf("%f", &trapezoidBase1)
  fmt.Println("Please enter base2 of trapezoid:")
  fmt.Scanf("%f", &trapezoidBase2)
  fmt.Println("Please enter height of trapezoid:")
  fmt.Scanf("%f", &trapezoidHeight)
  areaOfTrapezoid = (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2
  fmt.Println("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