1. Go 九九乘法表

方式一

package main

import "fmt"

func main() {
	// Iterate over the rows (1 to 9)
	for row := 1; row <= 9; row++ {
		// Iterate over the columns (1 to row)
		for col := 1; col <= row; col++ {
			// Calculate the product
			product := row * col

			// Print the product
			fmt.Printf("%d x %d = %d\t", row, col, product)
		}
		// Print a newline after each row
		fmt.Println()
	}
}

方式二

package main

import "fmt"

func printTable(row, col int) {
	if row > 9 || col > row {
		return // Base case: exit when row or col exceeds limits
	}

	product := row * col
	fmt.Printf("%d x %d = %d\t", row, col, product)

	// Print next column in the same row
	printTable(row, col+1)

	// If at the end of the row, move to the next row with col 1
	if col == row {
		fmt.Println()
		printTable(row+1, 1)
	}
}

func main() {
	printTable(1, 1)
}

相关推荐

  1. 1. Go 乘法表

    2024-07-11 01:36:03       7 阅读
  2. 【c语言】乘法表

    2024-07-11 01:36:03       40 阅读
  3. scala案例-- 乘法表

    2024-07-11 01:36:03       13 阅读
  4. 用python编写乘法表

    2024-07-11 01:36:03       43 阅读

最近更新

  1. MySQL——索引

    2024-07-11 01:36:03       0 阅读
  2. Log4j2原理及应用详解(十三)

    2024-07-11 01:36:03       0 阅读
  3. web学习笔记(八十二)uniapp

    2024-07-11 01:36:03       0 阅读
  4. git clone/push报错:HTTP Basic: Access denied

    2024-07-11 01:36:03       0 阅读
  5. 高等数学用到的初等数学

    2024-07-11 01:36:03       0 阅读
  6. JVM 在什么情况下会触发垃圾回收?

    2024-07-11 01:36:03       0 阅读

热门阅读

  1. Perl词法作用域:自定义编程环境的构建术

    2024-07-11 01:36:03       6 阅读
  2. SQL Server 设置端口详解

    2024-07-11 01:36:03       5 阅读
  3. MyBatis 框架核心及面试知识要点

    2024-07-11 01:36:03       7 阅读
  4. NLP - 基于bert预训练模型的文本多分类示例

    2024-07-11 01:36:03       6 阅读
  5. 二刷算法训练营Day57 | 动态规划(17/17)

    2024-07-11 01:36:03       6 阅读
  6. 自定义业务非受检异常

    2024-07-11 01:36:03       7 阅读
  7. GPT-5 一年半后发布?对此你有何期待?

    2024-07-11 01:36:03       6 阅读