求两个自然数的最大公约数.frm
来自「各种排序查找法与一些优秀的算法,包括二分查找,利用递推公式计算(裴波拉契数列),」· FRM 代码 · 共 89 行
FRM
89 行
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3075
ClientLeft = 60
ClientTop = 465
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3075
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 3480
TabIndex = 6
Top = 1920
Width = 855
End
Begin VB.TextBox Text3
Height = 375
Left = 1440
TabIndex = 5
Top = 1920
Width = 1695
End
Begin VB.TextBox Text2
Height = 375
Left = 1440
TabIndex = 1
Top = 1200
Width = 1695
End
Begin VB.TextBox Text1
Height = 375
Left = 1440
TabIndex = 0
Top = 480
Width = 1695
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "最大公约数"
Height = 180
Left = 360
TabIndex = 4
Top = 2040
Width = 900
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "自然数 n"
Height = 180
Left = 360
TabIndex = 3
Top = 1320
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "自然数 m"
Height = 180
Left = 360
TabIndex = 2
Top = 600
Width = 720
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim m As Long, n As Long, r As Long
m = Val(Text1.Text)
n = Val(Text2.Text)
If m < 1 Or n < 1 Then
Text3.Text = "数据错误!"
Else
Do
r = m Mod n
m = n
n = r
Loop Until r = 0
Text3.Text = CStr(m)
End If
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?