如题所述
Imports System.Math
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a, b As Integer
Dim min, max As Integer
min = 100
max = 300
Randomize()
a = CInt((max - min) * Rnd() + min)
b = CInt((max - min) * Rnd() + min)
TextBox1.Text = a
TextBox2.Text = b
TextBox3.Text = getGreatestDivisor(a, b)
End Sub
Private Function getGreatestDivisor(ByVal m As Integer, ByVal n As Integer) As Integer
Dim c As Integer
c = m Mod n
While (c <> 0)
m = n
n = c
c = m Mod n
End While
Return n
End Function
End Class
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a, b As Integer
Dim min, max As Integer
min = 100
max = 300
Randomize()
a = CInt((max - min) * Rnd() + min)
b = CInt((max - min) * Rnd() + min)
TextBox1.Text = a
TextBox2.Text = b
TextBox3.Text = getGreatestDivisor(a, b)
End Sub
Private Function getGreatestDivisor(ByVal m As Integer, ByVal n As Integer) As Integer
Dim c As Integer
c = m Mod n
While (c <> 0)
m = n
n = c
c = m Mod n
End While
Return n
End Function
End Class
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-12-03
如图所示,望采纳。。。