Golang : Generate multiplication table from an integer example
My son is 6 years old now and it is about the right time to expose him to some basic programming and math beyond simple plus and minus. Right now he is learning to code in Golang(easier to grasp) and a little bit of Java(he is having a hard time understanding).
NOTE : While it is good to be able to instruct a computer to generate multiplication table, but I still hope that he is able to memorize the multiplication table from 1 to 12 as he progresses in his education.
Here you go!
package main
import (
"fmt"
)
func main() {
var i int
fmt.Print("Enter an integer to generate the multiplication table : ")
fmt.Scanln(&i)
for n := 1; n <= 12; n++ {
fmt.Println(i, " X ", n, " = ", i*n)
}
}
Sample output:
Enter an integer to generate the multiplication table : 12
12 X 1 = 12
12 X 2 = 24
12 X 3 = 36
12 X 4 = 48
12 X 5 = 60
12 X 6 = 72
12 X 7 = 84
12 X 8 = 96
12 X 9 = 108
12 X 10 = 120
12 X 11 = 132
12 X 12 = 144
See also : Golang : Math pow(the power of x^y) example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.7k Golang : Get expvar(export variables) to work with multiplexer
+12.2k Golang : Get month name from date example
+9.8k Golang : Check if user agent is a robot or crawler example
+8.1k Golang : Auto-generate reply email with text/template package
+7.4k Golang : Detect sample rate, channels or latency with PortAudio
+36.2k Golang : Convert date or time stamp from string to time.Time type
+6.3k Golang : Handling image beyond OpenCV video capture boundary
+14.2k Android Studio : Use image as AlertDialog title with custom layout example
+12.5k Golang : Transform comma separated string to slice example
+8.5k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+10.2k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+8.1k Golang : HttpRouter multiplexer routing example