------------------
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Label1のテキスト(数値)を取得し、空白で分割し、整数配列に変換する
Dim input As String = TextBox1.Text
Dim numbers As String() = input.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
Dim integers As Integer() = Array.ConvertAll(numbers, Function(str) Integer.Parse(str))
' 最大公約数と最小公倍数の初期値を設定
Dim gcdResult As Integer = integers(0)
Dim lcmResult As Integer = integers(0)
' 入力された整数の最大公約数を計算
For i As Integer = 1 To integers.Length - 1
gcdResult = GCD(gcdResult, integers(i))
Next
' 最小公倍数を計算するために、各数の積を最大公約数で割る
For Each num As Integer In integers
lcmResult = LCM(lcmResult, num)
Next
' 結果をLabel1とLabel2に表示する
Label1.Text = "GCD: " & gcdResult.ToString()
Label2.Text = "LCM: " & lcmResult.ToString()
End Sub
------------------
' 最大公約数(Greatest Common Divisor)を求める関数
Function GCD(ByVal a As Integer, ByVal b As Integer) As Integer
While b <> 0
Dim temp As Integer = b
b = a Mod b
a = temp
End While
Return Math.Abs(a)
End Function
------------------
' 最小公倍数(Least Common Multiple)を求める関数
Function LCM(ByVal a As Integer, ByVal b As Integer) As Integer
Return (a * b) / GCD(a, b)
End Function
------------------
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.ResetText()
Label1.ResetText()
Label2.ResetText()
End Sub
------------------
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End
End Sub
End Class
------------------