'求 N1,N2 的最大公因數
Public Class Form1
Dim i
Dim str1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim n1 = 24
Dim n2 = 60
'Dim n1 = Val(InputBox("請輸入第一個數:"))
'Dim n2 = Val(InputBox("請輸入第二個數:"))
For i = 1 To n1
If n1 Mod i = 0 And n2 Mod i = 0 Then
str1 = i
End If
Next
MsgBox(str1)
End Sub
End Class
沒有留言:
張貼留言