ProgrammingHardCompetitive coding (CP)

What is printed?

What is printed?
#include <stdio.h>
int calls = 0;
int g(int a, int b) {
    calls++;
    return b ? g(b, a % b) : a;
}
int main(void) {
    int r = g(2025, 1500);
    printf("%d %d", r, calls);
}
  1. A. 75 4
  2. B. 25 5
  3. C. 75 5
  4. D. 75 6

Correct answer: C. 75 5

Euclid's recursion gives gcd(2025, 1500) = 75 through the calls (2025, 1500), (1500, 525), (525, 450), (450, 75) and (75, 0), which is five calls.

More C Programming questions

Exams that ask this topic