Private Sub CommandButton1_Click()
's=1-2+3...+n ==>
'当n为偶数时,上式是 n/2 个(-1)的和,所以有
'S=(-1)×( n/2) =- n/2 ;
'当n为奇数时,上式是 n-1/2 个(-1)的和,再加上最后一项(-1)n+1?n=n,所以有
'S=(-1)× n-1/2 +n= n+1/2 .
Dim n As Integer
n = Cells(1, 1)
Dim sum As Double
If (n Mod 2 = 0) Then
sum = -n / 2
Else
sum = (n + 1) / 2
End If
Cells(2, 1) = sum
End Sub