1. 畫面上拉三個 TextBox,一個 Button。
2. 程式碼如下:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  Dim a, b, c, gcd As Integer
  a = Integer.Parse(TextBox1.Text)
  b = Integer.Parse(TextBox2.Text)
  c = Integer.Parse(TextBox3.Text)
  gcd = GetGCD(a, GetGCD(b, c))
  Response.Write("最大公因數=" & gcd)
End Sub

Private Function GetGCD(ByVal x, ByVal y)
  Dim q As Integer
  Do
    q = x Mod y
    If q <> 0 Then
      x = y
      y = q
    End If
  Loop Until q = 0
  Return y
End Function
arrow
arrow
    全站熱搜

    浮雲 發表在 痞客邦 留言(0) 人氣()