LCM of two numbers
This code shows how to find the LCM of two numbers.
Private Sub LCM()
Dim intFirst, intSecond As Integer
Dim intFirst1, intSecond1 As Integer
Dim strOutput As String
intFirst = 200
intSecond = 500
strOutput = "LCM of " & intFirst & " AND " & intSecond & " is "
If intFirst = 0 or intSecond = 0 Then
'If any of the two is 0 then lcm is 0.
MessageBox.Show("LCM=0")
Exit Sub
Else
'Add the numbers in the given sequence as below till
'both numbers are equal.Variables ending with 1 are
'used for saving the value temporarily.
intFirst1 = intFirst
intSecond1 = intSecond
While intFirst <> intSecond
If (intFirst < intSecond) Then
intFirst = intFirst + intFirst1
Else
intSecond = intSecond + intSecond1
End If
End While
End If
MessageBox.Show(strOutput & intFirst)
End Sub