求VB编程,两个按钮"奇数和","偶数和"。输入整数n,计算1~n之间的奇数和,偶数和,并显示 30
1个回答
展开全部
Private Sub Command1_Click()
Dim n As Integer
Dim s As Double
s = 0
n = Val(Text1.Text)
For i = 1 To n
If i Mod 2 = 1 Then s = s + i
Next i
Text3.Text = s
End Sub
Private Sub Command2_Click()
Dim n As Integer
Dim s As Double
s = 0
n = Val(Text1.Text)
For i = 1 To n
If i Mod 2 = 0 Then s = s + i
Next i
Text2.Text = s
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |