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.
Exit Sub
'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
intSecond = intSecond + intSecond1
End If
End While
End If
MessageBox.Show(strOutput & intFirst)
End Sub


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: