Here is the code (within a class):
Her is the output:
6
GCD of 270 and 192 is 0
The program '[16176] TestApp.exe' has exited with code 0 (0x0).
Calling module:
Debug.Print("GCD of " & Num1 & " and " & Num2 & " is " & myFact.GCD(Num1, Num2))
Issue:
Why does the return not give a '6' as it should?
Code:
Function GCD(Num1 As Integer, Num2 As Integer) As Integer
'Debug.Print("1st " & Num1 & " 2nd " & Num2)
' use Euclid's algorithm
' Greatest Common Divisor (GCD) of two integers A and B is the largest integer that divides both A and B.
If Num1 Mod Num2 = 0 Then
Debug.Print(Num2)
Return Num2
Else
GCD(Num2, Num1 Mod Num2)
End If
'Return
End Function
6
GCD of 270 and 192 is 0
The program '[16176] TestApp.exe' has exited with code 0 (0x0).
Calling module:
Debug.Print("GCD of " & Num1 & " and " & Num2 & " is " & myFact.GCD(Num1, Num2))
Issue:
Why does the return not give a '6' as it should?