用vb语言编写一个程序,随机生成两个100-300之间的正整数,显示他们,并求这两个数的最大公约数

如题所述

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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-12-03

如图所示,望采纳。。。

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网