This Go program to find the Square of a Number allows users to enter a numeric value. Next, it used the Arithmetic multiplication operator to find the square of that number.
package main
import "fmt"
func main() {
var sqnum int
fmt.Print("Enter the Number to find Square = ")
fmt.Scanln(&sqnum)
sqr := sqnum * sqnum
fmt.Println("\nThe Square of a Given Number = ", sqr)
}
Enter the Number to find Square = 9
The Square of a Given Number = 81
Golang program to find Square of a Number
This golang program creates a new function that returns the square of the given number.
package main
import "fmt"
func findSquare(x int) int {
return x * x
}
func main() {
var sqnum int
fmt.Print("Enter the Number to find Square = ")
fmt.Scanln(&sqnum)
sqr := findSquare(sqnum)
fmt.Println("\nThe Square of a Given Number = ", sqr)
}
