vb程序输入任意一个整数,求1到n的所有质数
答案:2 悬赏:40 手机版
解决时间 2021-03-26 04:29
- 提问者网友:酱爆肉
- 2021-03-25 22:59
vb程序输入任意一个整数,求1到n的所有质数
最佳答案
- 五星知识达人网友:玩世
- 2021-03-25 23:30
Private Sub Form_Click()
Dim i, j As Integer
Dim flag As Boolean
Dim a As Integer
a = Val(InputBox("请输入一个整数"))
For i = 2 To a
flag = False
For j = 1 To i / 2
If i Mod j = 0 Then
flag = True
Exit For
End If
Next
If flag = False Then
Print i
End If
Next
End Sub
全部回答
- 1楼网友:怙棘
- 2021-03-26 00:27
Private Sub Command1_Click()
Dim k As Integer, i As Integer, m As Integer
k = Val(InputBox("请输入一个整数"))
For i = 1 To k
If ss(i) Then
Print i;
m = m + 1
If m Mod 8 = 0 Then Print
End If
Next i
End Sub
Function ss(n As Integer) As Boolean
ss = True
If n <= 1 Then
ss = False
Exit Function
End If
For i = 2 To n - 1
If n Mod i = 0 Then
ss = False
Exit Function
End If
Next i
End Function
Dim k As Integer, i As Integer, m As Integer
k = Val(InputBox("请输入一个整数"))
For i = 1 To k
If ss(i) Then
Print i;
m = m + 1
If m Mod 8 = 0 Then Print
End If
Next i
End Sub
Function ss(n As Integer) As Boolean
ss = True
If n <= 1 Then
ss = False
Exit Function
End If
For i = 2 To n - 1
If n Mod i = 0 Then
ss = False
Exit Function
End If
Next i
End Function
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯