Go program to find Square of a Number

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)
}
Golang program to find Square of a Number 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.