 Go Program to Find Square of a Number using Functions – Programming Code Examples
Go

# Go Program to Find Square of a Number using Functions2 min read

How to write a Golang program to find the square root of a number is a common Go programming exercise. Go program for square root is also a popular question during college semester exams and various programming tests. If you are familiar with Go API then writing a Go program that can find the square root of a number using math library is not difficult. You just need to pass a double value and it returns a double which is the square root of the number you passed.

In the next section, we will see the complete code example of finding the square root of a number from the Go program. Another Go coding questions which is very popular and related to programming exercise is writing Go program to find prime numbers, if you are going to appear in Go interviews than its worth looking.

Before discussing the square root code in GO programming language, let’s understand the term square root first.

## Square Root

The square of a number is that number times itself. In other terms, when we multiply an integer by itself we call the product the square of the number. Mathematically,  the square of a number is given as,

Square of n = n*n

For example, the square of number 4 is 4*4 = 16

The square root is just the opposite of the square. The square root of a number, n, is the number that gives n when multiplied by itself. Mathematically, the square root of a number is given as,

Square Root of n = √n

Now that you know what square and square root of a number are, let’s see different ways to calculate them in Golang.

Example 1:

Output:

Example 2:

Output:

Example 3:

Output: