VB 将1~500之间能被7或11整除 但不被3和4整除的所有整数存放在一维数组中 并输出

2026年09月23日 18:02
有2个网友回答
网友(1):

dim arr() as string
dim counter as integer

counter =0
for i=1 to 500
 if (i Mod 7 = 0 or i Mod 11 = 0) and i Mod 3 <> 0 and i Mod 4 <> 0 Then
     counter =  counter + 1 
     arr(counter)=i
 end if
next i

网友(2):

Private Sub Command1_Click()
Dim i%, j%
Dim a() As Integer
For i = 1 To 500
If (i Mod 7 = 0 Or i Mod 11 = 0) And i Mod 4 <> 0 And i Mod 3 <> 0 Then
j = j + 1
ReDim a(j) As Integer
a(j) = i
Print a(j);
End If
Next

End Sub