6-3 编写函数计算Sn=a+aa+aaa+…+aa…a
时间: 2024-01-09 14:05:03 浏览: 140
C语言课程设计
以下是计算Sn=a+aa+aaa+...+aa...a的函数示例:
```python
def calculate_Sn(a, n):
Sn = 0
for i in range(1, n+1):
term = int(str(a) * i)
Sn += term
return Sn
a = 6
n = 3
result = calculate_Sn(a, n)
print("Sn =", result) # 输出:Sn = 738
```
阅读全文