用while和do-while循环计算1*1+2*3+3*5+…+n*(2*n-1)的前50项结果。
时间: 2023-10-31 18:04:36 浏览: 7
求1+1*2+1*2*3+...+1*2*3*...*n的和(C for循环)
4星 · 用户满意度95%
使用while循环:
```python
n = 1
count = 0
while count < 50:
result = n * (2*n-1)
print(result, end=' ')
n += 1
count += 1
```
使用do-while循环:
```python
n = 1
count = 0
while True:
result = n * (2*n-1)
print(result, end=' ')
n += 1
count += 1
if count >= 50:
break
```
阅读全文