package main import "fmt" func printPatternRecursive(n int) { if n <= 0 { return } // 递归调用下一层 printPatternRecursive(n - 1) // 打印当前层的数字 for i := 0; i < n; i++ { fmt.Printf("%d ", n) } fmt.Println() } func main() { fmt.Println("递归算法:") printPatternRecursive(5) }