Do While (r 0) ←特别这个(r0)!m = n:n = r r = m Mod n LoopDo While (r 0) ←特别这个(r0)!m = n:n = rr = m Mod nLoop

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/05 16:34:58

Do While (r 0) ←特别这个(r0)!m = n:n = r r = m Mod n LoopDo While (r 0) ←特别这个(r0)!m = n:n = rr = m Mod nLoop
Do While (r 0) ←特别这个(r0)!m = n:n = r r = m Mod n Loop
Do While (r 0) ←特别这个(r0)!
m = n:n = r
r = m Mod n
Loop

Do While (r 0) ←特别这个(r0)!m = n:n = r r = m Mod n LoopDo While (r 0) ←特别这个(r0)!m = n:n = rr = m Mod nLoop
这是一个利用辗转相除求两个数m和n最大公约数的程序中的一段,其中这一段是最中心的算法.
完整的求m和n的最大大约数的程序如下:
Private Sub Command1_Click()
Dim m As Integer
Dim n As Integer
Dim r As Integer
m = InputBox("请输入一个正整数m:")
n = InputBox("请输入一个正整数n:")
If m < n Then
temp = m
m = n
n = temp
End If
r = m Mod n
Do While r 0 'r = m Mod n,即两数相除的余数,余数为0时将不再循环,不为0时一起除下去
m = n
n = r
r = m Mod n
Loop
Print n
End Sub