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 While Not EOF(1) Input #1, X, Y If X <> 0 And Y <> 0 Then Call Run(X, Y) End If Loop Close Close End End Sub
Sub Run(a, b)
If a = b Then Print #2, a Else If a > b Then Call Run(a - b, b) If b > a Then Call Run(a, b - a) End If
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 Then Exit Do
Call T(x, y)
Loop Until x = 0
Close #2 Close #1 End End Sub
Sub T(A, B) If A = B Then Print #2, A Else If A > B Then Call T(A - B, B) If B > A Then Call T(A, B - A) End If End Sub
Dim X As Integer, Y As Integer
回覆刪除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 While Not EOF(1)
Input #1, X, Y
If X <> 0 And Y <> 0 Then
Call Run(X, Y)
End If
Loop
Close
Close
End
End Sub
Sub Run(a, b)
If a = b Then
Print #2, a
Else
If a > b Then Call Run(a - b, b)
If b > a Then Call Run(a, b - a)
End If
End Sub
又複習一次輾轉相除法
回覆刪除:D
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 Then Exit Do
Call T(x, y)
Loop Until x = 0
Close #2
Close #1
End
End Sub
Sub T(A, B)
If A = B Then
Print #2, A
Else
If A > B Then Call T(A - B, B)
If B > A Then Call T(A, B - A)
End If
End Sub
佑好,arro好,
回覆刪除程式正確。