Dim x%, y% Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, x, y If x <> 0 And y <> 0 Then Call abc(x, y) Loop Until x = 0 Close Close End End Sub Sub abc(a, b) If a = b Then Print #2, a Else If a > b Then Call abc(a - b, b) If b > a Then Call abc(a, b - a) End If End Sub
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, X1, X2 If X1 = X2 And X1 = 0 Then Exit Do r = X1 Mod X2 If r <> 0 Then Y1 = X1 Y2 = X2 Do Until r = 0 Y1 = Y2 Y2 = r r = Y1 Mod Y2 Loop End If Print #2, Y2 Loop Until X1 = 0 Close #2 Close #1 End End Sub
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Do Input #1, x, y If x = 0 And y = 0 Then Exit Do Call g(Val(x), Val(y)) Loop Close #2 Close #1 End End Sub
Sub g(a, b) t = a Mod b a = b: b = t If t <> 0 Then Call g(a, b) Else Print #2, a End If End Sub
Dim x%, y%
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, x, y
If x <> 0 And y <> 0 Then Call abc(x, y)
Loop Until x = 0
Close
Close
End
End Sub
Sub abc(a, b)
If a = b Then
Print #2, a
Else
If a > b Then Call abc(a - b, b)
If b > a Then Call abc(a, b - a)
End If
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, X1, X2
If X1 = X2 And X1 = 0 Then Exit Do
r = X1 Mod X2
If r <> 0 Then
Y1 = X1
Y2 = X2
Do Until r = 0
Y1 = Y2
Y2 = r
r = Y1 Mod Y2
Loop
End If
Print #2, Y2
Loop Until X1 = 0
Close #2
Close #1
End
End Sub
兩位程式正確 遞迴會更好做
回覆刪除Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Do
Input #1, x, y
If x = 0 And y = 0 Then Exit Do
Call g(Val(x), Val(y))
Loop
Close #2
Close #1
End
End Sub
Sub g(a, b)
t = a Mod b
a = b: b = t
If t <> 0 Then
Call g(a, b)
Else
Print #2, a
End If
End Sub