logo image

Go language program to calculate square area and circumference


Following program shows you how to calculate square area and circumference. This program gets square length from user and calculates area and circumference and prints them using following formulas Area = length X length Circumference = 4 X length

package main

import "fmt"

func main() {

  var squareLength float64
  var areaOfSquare float64
  var circumferenceOfSquare float64
  fmt.Println("Enter length of square:")
  fmt.Scanf("%f", &squareLength)
  areaOfSquare = squareLength * squareLength
  fmt.Println("Area of square is: " , areaOfSquare)
  circumferenceOfSquare = 4 * squareLength
  fmt.Println("Circumference of square is: " , circumferenceOfSquare)


Enter length of square:
Area of square is:  64
Circumference of square is:  32