Connect with one of the following accounts


Please wait while we redirect...

Views: 129   

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

package main

import "fmt"

func main() {

  var rectangleLength float64
  var rectangleWidth float64
  var areaOfRectangle float64
  var circumferenceOfRectangle float64
  fmt.Println("Enter length of rectangle:")
  fmt.Scanf("%f", &rectangleLength)
  fmt.Println("Enter width of rectangle:")
  fmt.Scanf("%f", &rectangleWidth)
  areaOfRectangle = rectangleLength * rectangleWidth
  fmt.Println("Area of rectangle is: " , areaOfRectangle)
  circumferenceOfRectangle = 2 * (rectangleLength) + 2 * (rectangleWidth)
  fmt.Println("Circumference of rectangle is: " , circumferenceOfRectangle)


Enter length of rectangle:
Enter width of rectangle:
Area of rectangle is:  875
Circumference of rectangle is:  120

On By

Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News