2018-10-13 23:30:21 +03:00
|
|
|
// Copyright © 2018 Inanc Gumus
|
|
|
|
// Learn Go Programming Course
|
|
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
//
|
2019-10-30 19:34:44 +03:00
|
|
|
// For more tutorials : https://learngoprogramming.com
|
|
|
|
// In-person training : https://www.linkedin.com/in/inancgumus/
|
|
|
|
// Follow me on twitter: https://twitter.com/inancgumus
|
2018-10-13 23:30:21 +03:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-22 12:25:30 +03:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2018-10-13 23:30:21 +03:00
|
|
|
)
|
|
|
|
|
2018-10-22 12:25:30 +03:00
|
|
|
func main() {
|
|
|
|
args := os.Args
|
2018-10-13 23:30:21 +03:00
|
|
|
|
2018-10-22 12:25:30 +03:00
|
|
|
if len(args) != 2 {
|
|
|
|
fmt.Println("Give me the size of the table")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
size, err := strconv.Atoi(args[1])
|
|
|
|
if err != nil || size <= 0 {
|
|
|
|
fmt.Println("Wrong size")
|
|
|
|
return
|
|
|
|
}
|
2018-10-13 23:30:21 +03:00
|
|
|
|
|
|
|
// print the header
|
|
|
|
fmt.Printf("%5s", "X")
|
2018-10-22 12:25:30 +03:00
|
|
|
for i := 0; i <= size; i++ {
|
2018-10-13 23:30:21 +03:00
|
|
|
fmt.Printf("%5d", i)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
|
2018-10-22 12:25:30 +03:00
|
|
|
for i := 0; i <= size; i++ {
|
2018-10-13 23:30:21 +03:00
|
|
|
// print the vertical header
|
|
|
|
fmt.Printf("%5d", i)
|
|
|
|
|
|
|
|
// print the cells
|
2018-10-22 12:25:30 +03:00
|
|
|
for j := 0; j <= size; j++ {
|
2018-10-13 23:30:21 +03:00
|
|
|
fmt.Printf("%5d", i*j)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
}
|