单机窗体时,求-1+3-5+7-9.....+99的结果并输出 VB题
4个回答
展开全部
Private Sub Command1_Click()
For i = 1 To 99 Step 2
if i mod 4 = 1 then s = s + i else s = s - i
Next i
Print s
End Sub
For i = 1 To 99 Step 2
if i mod 4 = 1 then s = s + i else s = s - i
Next i
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
For i = 1 To 99 Step 2
t = ((i + 1) / 2) Mod 2
s = s + i * (-1) ^ t
Next i
Print s
End Sub
For i = 1 To 99 Step 2
t = ((i + 1) / 2) Mod 2
s = s + i * (-1) ^ t
Next i
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
变量在使用前最好先定义,养成良好的习惯
dim i as integer,s as integer
for i = 1 to 49
s = s + (-1)^i*(2*i+1)
next i
printf s
dim i as integer,s as integer
for i = 1 to 49
s = s + (-1)^i*(2*i+1)
next i
printf s
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询