Go language program to calculate trapezoid circumference

Views: 18   

Following program shows you how to calculate trapezoid circumference.
This program gets trapezoid bases and sides from user and calculates circumference and prints it using following formula
Circumference = base1 + base2 + side1 +side2

package main

import "fmt"

func main() {

  var trapezoidBase1 float64
  var trapezoidBase2 float64
  var trapezoidSide1 float64
  var trapezoidSide2 float64
  var circumferenceOfTrapezoid 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 side1 of trapezoid:")
  fmt.Scanf("%f", &trapezoidSide1)
  fmt.Println("Please enter side2 of trapezoid:")
  fmt.Scanf("%f", &trapezoidSide2)
  circumferenceOfTrapezoid = trapezoidBase1 + trapezoidBase2 + trapezoidSide1 + trapezoidSide2
  fmt.Println("Circumference of trapezoid is: " , circumferenceOfTrapezoid)
}

Output:

Please enter base1 of trapezoid:
 5
Please enter base2 of trapezoid:
 8
Please enter side1 of trapezoid:
 12
Please enter side2 of trapezoid:
 12
Circumference of trapezoid is:  37
On By