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       24 阅读
  2. 【c语言】乘法表

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

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

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 01:36:03       53 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 01:36:03       55 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 01:36:03       46 阅读
  4. Python语言-面向对象

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

热门阅读

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

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

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

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

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

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

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

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