编写程序,求下面数列的前20项的和,结果保留2位小数.1,-1/(1+3),1/(1+3+5),...,(-1)^(n+1)/(1+3+5+...+
问题描述:
编写程序,求下面数列的前20项的和,结果保留2位小数.1,-1/(1+3),1/(1+3+5),...,(-1)^(n+1)/(1+3+5+...+
答
Dim i,t,s1 As Integer
Dim s As Single
s = 0
s1 = 0
t = 1
For i = 1 To 20
s1 = s1 + 2 * i - 1
s = s + t / s1
t = -t
Next i
Print Round(s,2)