Golang Program to Print the Multiplication Table of a Given Number

Go ProgrammingServer Side ProgrammingProgramming

Steps

  • Read a number and store it in a variable.
  • Print the multiplication table of the given number.
Enter the number to print the table for: 7
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
Enter the number to print the table for: 17
17 x 1 = 7
17 x 2 = 34
17 x 3 = 51
17 x 4 = 68
17 x 5 = 85
17 x 6 = 102
17 x 7 = 119
17 x 8 = 136
17 x 9 = 153
17 x 10 = 170

Explanation

  • User must enter a number.
  • Using a print statement, print the multiplication table of the given number.

Example

 Live Demo

package main
import "fmt"
func main(){
   var n int
   fmt.Print("Enter the number to print the multiplication table:")
   fmt.Scanf("%d", &n)
   for i:=1; i<11; i++ {
      fmt.Println(n, "x", i, "=", n*i)
   }
}

Output

Enter the number to print the multiplication table: 7
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
raja
Published on 31-Jul-2021 15:29:55
Advertisements