Question: The gcd program of Example 1.20 might also be written int main() { int i = getint(), j = getint(); while (i != j) {
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?
Step by Step Solution
3.44 Rating (163 Votes )
There are 3 Steps involved in it
The difference between the two programs is in the two assignment statements i i j and j j i versus i ... View full answer
Get step-by-step solutions from verified subject matter experts
