The gcd program of Example 1.20 might also be written int main() { int i = getint(),

Question:

The gcd program of Example 1.20 might also be written

int main() {
    int i = getint(), j = getint();
    while (i != j) {
        if (i > j) i = i % j;
        else j = j % i;
}
putint(i);

}

Does this program compute the same result? If not, can you fix it? Under what circumstances would you expect one or the other to be faster?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: