I'm trying to make a Fraction Calculator in VB.NET, but I'm stuck with the LCM part. I found some code on the internet:
Public Shared Function GCD(a As Integer, b As Integer) As Integer
If a = 0 Then
Return b
End If
Do While b <> 0
If a > b Then
a = a - b
Else
b = b - a
End If
Loop
Return a
End Function
Public Shared Function LCM(a As Integer, b As Integer) As Int64
Return Math.BigMul(Math.Abs(a), Math.Abs(b)) \ GCD(a, b)
End Function
But when I'm trying to get the LCM, it shows me the second number every time! e.g When I try to get the LCM of 2 and 3 it shows me 3.
How can I get the LCM without GCD?