CSC 344 - Algorithms and Complexity

Assignment #9 - Turning a recursive method into an interative method

Due Monday, May 1, 2017

The C expression m % n yields the remainders of m divided by n. Define the greatest common divisor (GCD) of two integers x and y by:
gcd(x, y) = yif (y <= x && x % y == 0)
gcd(x, y) = gcd(y, x)if (x < y)
gcd(x, y) = gcd(y, x % y)otherwise

Rewrite the algorithm as an iterative method in C/C++/Java (your choice). Write a main program (both method and main program properly commented) that will run it with the data sets below:
xy
328
2415
6448

[Back to the Assignments Page]