GO Program to Calculate Area of Rectangle and Square
Check the scope of variable declare outside the main function and (l,b) both variables declare in a single statement. In this example, we are calculating are of rectangle and square.
Example
package main
import "fmt"
var area int // Variable declare outside the main function
func main(){
var l,b int //Declaration of multiple Variables
fmt.Print("Enter Length of Rectangle : ")
fmt.Scan(&l)
fmt.Print("Enter Breadth of Rectangle : ")
fmt.Scan(&b)
area = l * b
fmt.Println("Area of Rectangle : ",area) //move to new line
fmt.Print("Enter Length of Square : ")
fmt.Scan(&l)
area = l*l
fmt.Print("Area of Square : ",area)
}
Most Helpful This Week
GO language program with example of Array Reverse Sort Functions for integer and strings
GO Program to Find the Largest Number Among Three Numbers
Program in Go language to Program to Add Two Matrix Using Multi-dimensional Arrays
Example to use various String Functions in Go Language
GO supports the standard arithmetic operators: (Addition, Subtraction, Multiplication, Division,Remainder)
GO Program to take user input and addition of two strings