📄 最大公约数函数定义.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "例[8-4]求最大公约数"
ClientHeight = 1515
ClientLeft = 60
ClientTop = 345
ClientWidth = 5430
LinkTopic = "Form1"
ScaleHeight = 1515
ScaleWidth = 5430
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "求最大公约数"
Height = 495
Left = 2786
TabIndex = 5
Top = 828
Width = 2415
End
Begin VB.TextBox Text2
Height = 495
Left = 1309
TabIndex = 3
Top = 791
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 1309
TabIndex = 2
Top = 191
Width = 1215
End
Begin VB.Label Label4
BorderStyle = 1 'Fixed Single
Height = 495
Left = 3986
TabIndex = 6
Top = 191
Width = 1215
End
Begin VB.Label Label3
Caption = "最大公约数为:"
Height = 495
Left = 2756
TabIndex = 4
Top = 198
Width = 1335
End
Begin VB.Label Label2
Caption = "请输入数二:"
Height = 495
Left = 229
TabIndex = 1
Top = 791
Width = 1215
End
Begin VB.Label Label1
Caption = "请输入数一:"
Height = 495
Left = 229
TabIndex = 0
Top = 191
Width = 1215
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 a As Integer, b As Integer, x As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
If a < b Then '保证a>=b
x = a
a = b
b = x
End If
Label4.Caption = Str(gcd(a, b)) '调用函数gcd求最大公约数
End Sub
'求最大公约数的函数
Function gcd(ByVal x As Integer, ByVal y As Integer) As Integer
Dim ret As Integer
Do While y <> 0
ret = x Mod y
x = y
y = ret
Loop
gcd = x
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -