用vb编写程序 输入一个正整数n,输出1~n中所有的素数
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
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
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询