用vb语言编写一个程序,随机生成两个100-300之间的正整数,显示他们,并求这两个数的最大公约数
2个回答
展开全部
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询