Go language program to calculate rectangle area and circumference
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)
}
Output:
Enter length of rectangle:
25
Enter width of rectangle:
35
Area of rectangle is: 875
Circumference of rectangle is: 120