Menu Close

Go – Program to calculate area of Rectangle and Square

Here, We are going to write a program to calculate area of Rectangle and Square in go golang. Area of rectangle is multiplication of length and breadth i.e length * breadth whereas area of Square is square of length i.e length * length.

Algorithm:

  • Get the length and breadth of rectangle
  • Calculate the area of rectangle by multiplying length and breadth
  • Calculate the area of square by squaring the length

Example with code:

package main
 
import "fmt"
 
func main(){

  var length, breadth = 3, 4

  var area int

  area = length * breadth

  fmt.Println("Area of Rectangle : ", area)
    
  area = length * length

  fmt.Print("Area of Square : ", area)

}

Output:

Area of Rectangle :  12
Area of Square : 9

To learn more about golang, Please refer given below link.

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang

4 Comments

  1. class

    Right here is the perfect site for everyone who wants to find out
    about this topic. You know so much its almost tough to argue with you (not that I really would want to…HaHa).
    You definitely put a new spin on a subject that has been discussed for decades.
    Great stuff, just wonderful!

Leave a Reply

Your email address will not be published. Required fields are marked *