Go language program to calculate triangle area

Views: 141   

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)


Enter the base of triangle:
Enter the height of triangle:
Area of triangle is:  90
On By