请使用伪代码表达下面这个算式 1+1/2+1/3+1/4+1/5+1/7+1/8+…+1/20
时间: 2023-12-01 21:02:56 浏览: 96
A5_1_java编程_A5/1算法_
使用伪代码表达下面这个算式:
```
sum = 1.0
for i in range(2, 21):
if i == 6 or i == 9 or i == 10 or i == 12 or i == 14 or i == 15 or i == 16 or i == 18 or i == 20:
continue
if i % 2 == 0:
sum = sum - 1.0 / i
else:
sum = sum + 1.0 / i
print(sum)
```
阅读全文