GO Program to Generate Multiplication Table

For a better understanding of this example, we always recommend you to learn the basic topics of Golang programming listed below:

We know a multiplication table is a mathematical table that is used to understand the multiplication operation for an algebraic system. It helps you to work out mathematical problems far quicker and easier.

How to implement multiplication table in Golang?

In this section, we’ll focus our attention to generate the multiplication table of a number using the GO programming language. Here user can read the input number num for which the multiplication table is to be generated and read the end value e_range until which the table has to be generated.

We are using fmt.scanln() function for reading these values from the screen. The function fmt.println() is used to print anything, data or results to the output screen. These functions are defined under the fmt package. So we should import the “fmt” package into the program to use these functions. 

In this program, it will take an integer input num from the user and generate the multiplication tables up to end value e_range by using a for loop

Given below are the steps which are used in the Go program.

ALGORITHM 

STEP 1: Declare the variables num and e_range
STEP 2: Read the input number num for which the multiplication table is to be generated.
STEP 3: Read the end value e_range until which the table has to be generated.
STEP 4: Using for loop from i=1 to e_range display the multiplication table values by calculating the mutiples num x i

GO Source Code

                                          package main
import "fmt"
func main(){
    var num int
    var e_range int
    fmt.Print("Enter an Integer Number: ")
    fmt.Scan(#)
    fmt.Print("Enter the range or end value: ")
    fmt.Scan(&e_range)


    for i:=1; i<=e_range; i++ {
        fmt.Println(num," X ",i," = ",num*i)
    }
}
                                      

OUTPUT

Enter an Integer Number: 2
Enter the range or end value: 10
2  X  1  =  2
2  X  2  =  4
2  X  3  =  6
2  X  4  =  8
2  X  5  =  10
2  X  6  =  12
2  X  7  =  14
2  X  8  =  16
2  X  9  =  18
2  X  10  =  20