Private Sub Form_Click()
Dim i As Long, A As Long
A = 0
For i = 1 To 200
If i Mod 5 = 0 And i Mod 7 = 0 Then
Print i
A = A + i
End If
Next
Print "以上是同时被5和7整除的数,和=" & A
End Sub
for循环1到200,执行除5为ture再除7 ,ture就垒加到变量里。
代码就不给了,很简单。
' 单击窗体函数里面的代码:
Dim i As Integer ' 从1~200
Dim count As Integer ' 保存所求的和
For i=1 to 200
If (i Mod 5 = 0) And (i Mod 7 = 0) Then
count = count + i
End If
Next i