GO Program to Generate Multiplication Table

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.

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 until which the table has to be generated.

We are using fmt.scanln() the function for reading these values from the screen. The function fmt.println() is used to print anything data or result 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 by using a "for loop".

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

ALGORITHM 

STEP 1: Import the package fmt
STEP 2: Open the main() to start the program, GO program execution starts with the main()
STEP 3: Declare the variables num and e
STEP 4: Read the input number num for which the multiplication table is to be generated.
STEP 5: Read the end value e until which the table has to be generated.
STEP 6: Assign loop variable i=1
STEP 7: Repeat step 8 until i < e reach
STEP 8: Display the multiplication table values in the given output format.(num * i = num*i)
STEP 9: Exit

GO Source Code

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

    i:=1
    /*     For loop as a Go's While     */
    for {
        if(i>e){
            break;
        }
        fmt.Println(num," X ",i," = ",num*i)
        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