怎样用Microsoft Visual Basic 6.0 中文版求1-100之间的偶数之和

2024-11-02 09:17:43
推荐回答(4个)
回答1:

Dim sum As Integer
Dim i As Integer

sum = 0

For i = 1 To 100
If i Mod 2 = 0 Then
sum = sum + i
End If
Next
MsgBox "总计:" + cstr(sum)

回答2:

Option Explicit
Dim sum As Integer
Dim i As Integer

Private Sub Command1_Click()
For i = 2 To 100 Step 2
sum = sum + i
Next
Print sum
End Sub

回答3:

dim i as integer,j as integer
for i=1 to 100
if i mod 2=0 then
j=j+i
endif
next i

j就是和

回答4:

for a=2 to 100 step 2
s=s+a
next

print S