Post

Learning Go: Day 1 - Table Generator

Learning Go: Day 1 - Table Generator

Starting a 30-day journey to build multiple programs in Go. This is Day 1.

What is Table?

A simple Go program that generates multiplication tables. Given a number, it outputs the multiplication table for that number.

Example:

1
2
3
4
5
6
Enter the table number
5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...

Repository

sapienfrom2000s/table

Project Structure

1
2
3
4
5
6
table/
├── go.mod
├── go.sum
├── main.go
└── table/
    └── table.go

Main Entry Point

The main.go file handles:

  • Reading user input
  • Calling the table generation function
  • Printing the results
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import (
	"fmt"
	"table"
)

func main() {
	var tableNumber int
	fmt.Println("Enter the table number")
	_, err := fmt.Scanln(&tableNumber)
	if err != nil {
		fmt.Printf("Error: %q occurred while reading user input", err)
	}

	t := table.GenerateTable(tableNumber)

	for _, v := range t.Table {
		fmt.Printf("%v x %v = %v", t.Number, v.Times, v.Value)
		fmt.Println()
	}
}

Tomorrow I’ll try to create an uptime tracker for websites.

This post is licensed under CC BY 4.0 by the author.