VB.net考试上机题目汇总
作者:dawncold 发布时间:July 14, 2011 分类:技术
只是更新一下代码,因为在mac中的mono工作得不太好!!
1.求两个数的最大公约数和最小公倍数:
Module Module1
Public Function Gcd(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
If num2 = 0 Then
Return num1
Else
Return Gcd(num2, num1 Mod num2)
End If
End Function
Public Sub Main()
Console.WriteLine("Input first num: ")
Dim num1 As Integer = Convert.ToInt32(Console.ReadLine())
Console.WriteLine("Input second num: ")
Dim num2 As Integer = Convert.ToInt32(Console.ReadLine())
Console.WriteLine("Gcd is :{0}", Gcd(num1, num2))
Console.WriteLine("Lcd is :{0}", (num1 * num2) / Gcd(num1, num2)) '两个数的积除以最大公约数就是最小公倍数
Console.ReadLine()
End Sub
End Module