logo image

Go language program to calculate triangle area

73


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

package main

import "fmt"

func main() {

  var triangleBase float64
  var triangleHeight float64
  var areaOfTriangle float64
  fmt.Println("Enter the base of triangle:")
  fmt.Scanf("%f", &triangleBase)
  fmt.Println("Enter the height of triangle:")
  fmt.Scanf("%f", &triangleHeight)
  areaOfTriangle = (triangleBase * triangleHeight) / 2
  fmt.Println("Area of triangle is: " , areaOfTriangle)
  }

Output:

Enter the base of triangle:
 12
Enter the height of triangle:
 15
Area of triangle is:  90