Go language program to calculate trapezoid area
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)
}
Output:
Please enter base1 of trapezoid:
12
Please enter base2 of trapezoid:
16
Please enter height of trapezoid:
18
Area of trapezoid is: 252