I need to create a program that finds the greatest common factor of two user entered numbers using this formula:
gcd(x, y) = gcd(x – y, y) if x >= y and gcd(x, y) = gcd(x,y-x) if x < y.
For example: gcd(72, 54) = gcd(72 – 54, 54) = gcd(18, 54)Since 72 > 54, we replace 72 with 72 – 54 = 18 and continue the loop with the new values
Iteration 2: gcd(18, 54) = gcd(18, 54 – 18) = gcd(18, 36) Since 18 < 54, we replace 54 with 54 – 18 = 36 and continue the loop with the new values
Iteration 3: gcd(18, 36) = gcd(18, 36 – 18) = gcd(18, 18) Since 18 < 36, we replace 36 with 36 – 18 = 18 and continue the loop with the new values
Iteration 4: gcd(18, 18) = gcd(18 – 18, 18) = gcd(0, 18) = 18 Since 18 >= 18, we replace the first 18 with 18 – 18 = 0 Since one of the values is 0 we do not continue the loop The nonzero value, 18, is the gcd.
Here's of the code I have so far:
I'm getting the error "Illegal start of expression."