用vb编写程序 输入一个正整数n,输出1~n中所有的素数

2024-11-18 15:32:16
推荐回答(1个)
回答1:

在窗体上放一个按钮,然后代码如下:
Private Sub Command1_Click()
Dim i, j, k As Integer
Dim p As Boolean
Dim a As Integer
k = 1
a = InputBox("请输入n值:")
For i = 2 To a
p = False
For j = 2 To a
If j >= i Then Exit For
If i Mod j = 0 Then p = True
Next j
If p = False Then
Print i;
If k Mod 5 = 0 Then Print
k = k + 1
End If
Next i
Print
End Sub