Dim a() As Integer
Dim n As Integer, i As Integer, j As Integer
n = Val(Text1.Text)
ReDim a(n)
For i = 1 To n
a(i) = i
Next i
a(1) = 2
i = 2
For i = 2 To Int(Sqr(n))
If a(i) <> 0 Then
j = i + 1
Do While j <= n
If a(j) <> 0 Then
If a(j) Mod a(i) = 0 Then
a(j) = 0
j = j + 1
Loop
Next i
我出学,自己根据称许图编的算n以内素数的程序,但运行时提示loop缺少do。
还请教有没有好的输出方法
Dim n As Integer, i As Integer, j As Integer
n = Val(Text1.Text)
ReDim a(n)
For i = 1 To n
a(i) = i
Next i
a(1) = 2
i = 2
For i = 2 To Int(Sqr(n))
If a(i) <> 0 Then
j = i + 1
Do While j <= n
If a(j) <> 0 Then
If a(j) Mod a(i) = 0 Then
a(j) = 0
j = j + 1
Loop
Next i
我出学,自己根据称许图编的算n以内素数的程序,但运行时提示loop缺少do。
还请教有没有好的输出方法
If a(i) <> 0 Then
j = i + 1
Do While j <= n
If a(j) <> 0 Then
If a(j) Mod a(i) = 0 Then
a(j) = 0
j = j + 1
Loop
Next i
改成:
For i = 2 To Int(Sqr(n))
If a(i) <> 0 Then
j = i + 1
Do While j <= n
If a(j) <> 0 Then
If a(j) Mod a(i) = 0 Then
a(j) = 0
end if
end if
j = j + 1
Loop
end if
Next i
For i = 2 To Int(Sqr(n))
If a(i) <> 0 Then
j = i + 1
Do While j <= n
If a(j) <> 0 Then
If a(j) Mod a(i) = 0 Then
a(j) = 0
End If
End If
End If
j = j + 1
Loop
End If
Next i
绝不可看目光只盯在loop与do上,还要看其间的if else endif有没有配套出现