My task is to make a sub program to calculate the greatest common divisor (factor) between two numbers. Here is my code thus far:
Sub HighestFactor() ' Sub program to calculate the greatest common factor between two numbers
'Declarations
Dim a As Integer
Dim b As Integer
Dim quotient As Single
'Inputs
a = Sheet1.Cells(14, 4).Value
b = Sheet1.Cells(15, 4).Value
'Process
If a < 0 And b < 0 Then
Math.Abs (a)
Math.Abs (b)
If a > b Then
'b = divisor
'a = dividend
quotient = a / b Mod (a / b)
a = (b * quotient) Mod (b * quotient)
This is where I am getting stuck. I am familiar with the Euclidean Algorithm needed for this problem. However, I am not sure if I am using the Mod function correctly. Also, I do not know how to loop this back for the algorithm to work. I need for the new dividend to be (b*quotient) and for the divisor to be (Mod b*quotient). For extremely large nnumbers, this could get tedious. I need this code to work for any two numbers.
I only know the basic looping
For i=1 To 5 Step 1
Sheet1.Cells(R,C).Value = Number
etc.
How do I loop such an algorithm without doing it number by number?
Bookmarks