📄 v6j04-15.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "判断素数"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 5640
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 5640
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "使用GoTo语句"
Height = 495
Left = 4230
TabIndex = 1
Top = 2040
Width = 1275
End
Begin VB.CommandButton Command2
Caption = "使用状态变量"
Height = 495
Left = 4200
TabIndex = 0
Top = 2580
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command2_Click() ' 单击命令按钮运行该事件函数
'使用状态变量
Dim i As Integer, m As Integer, tag As Boolean
j = 0
For m = 2 To 100 ' 对100以内的每个数判断其是否为素数
tag = True
For i = 2 To m - 1
If (m Mod i) = 0 Then tag = False 'm能被i整除,该m不是素数
Next i
If tag Then
Print m; " "; 'm不能被i=2~m-1整除,m是素数,显示
j = j + 1
If j = 10 Then j = 0: Print
End If
Next m
End Sub
Private Sub Command1_Click()
'使用GoTo语句
j = 0
For m = 2 To 100
For i = 2 To m - 1
If (m Mod i) = 0 Then GoTo NotNextM
Next i
Print m; " ";
j = j + 1
If j = 10 Then j = 0: Print
NotNextM:
Next m
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -