"""
递归示例 — 递归打印整数各位数字
"""

def print_digits(n):
    """递归按位打印整数（高位到低位）"""
    if n < 10:
        print(n, end=" ")
    else:
        print_digits(n // 10)
        print(n % 10, end=" ")

def print_triangle(n, current=1):
    """递归打印星号三角形"""
    if current > n:
        return
    print("*" * current)
    print_triangle(n, current + 1)

if __name__ == "__main__":
    n = 12345
    print(f"递归打印 {n} 的各位数字:")
    print_digits(n)
    print("\n\n递归三角形 (n=5):")
    print_triangle(5)
