用VB编程计算1-2+3-4+5-6…±n的值,n由文本框输入
展开全部
Private Sub Form_Click()
Dim n As Integer
Dim sum As Integer
sum = 0
n = Val(InputBox("输入一个整数:"))
For i = 0 To n
sum = sum + (-1) ^ (i - 1) * i
Next i
Print sum
End Sub
Dim n As Integer
Dim sum As Integer
sum = 0
n = Val(InputBox("输入一个整数:"))
For i = 0 To n
sum = sum + (-1) ^ (i - 1) * i
Next i
Print sum
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim i#
i# = InputBox("输入n")
If i# <= 0 Then
MsgBox "输入有误!"
Exit Sub
End If
If ( i# And 1 ) = 0 Then
MsgBox "结果为-1"
Else
MsgBox "结果为1"
End If
End Sub
Dim i#
i# = InputBox("输入n")
If i# <= 0 Then
MsgBox "输入有误!"
Exit Sub
End If
If ( i# And 1 ) = 0 Then
MsgBox "结果为-1"
Else
MsgBox "结果为1"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询