Answer:
7
Explanation:
#include <stdio.h>
int max2(int x, int y) {
int result = y;
if (x > y) {
result = x;
}
return result;
}
int max3(int x, int y, int z) {
return max2(max2(x,y),z);
}
int main() {
int a = 5, b = 7, c = 3;
printf("%d",max3(a, b, c));
printf("");
return 0;
}
Hi, first of all, next time you post the question, it would be nice to copy and paste like above. This will help us to read the code easily. Thanks for your cooperation.
We start from the main function:
The variables are initialized → a = 5, b = 7, c = 3
max3 function is called with previous variables and the result is printed → printf("%d",max3(a, b, c));
We go to the max3 function:
It takes 3 integers as parameters and returns the result of → max2(max2(x,y),z)
Note that max2 function is called two times here (One call is in another call actually. That is why we need to first evaluate the inner one and use the result of that as first parameter for the outer call)
We go to the max2 function:
It takes 2 integers as parameters. If the first one is greater than the second one, it returns first one. Otherwise, it returns the second one.
First we deal with the inner call. max2(x,y) is max2(5,7) and the it returns 7.
Now, we need to take care the outer call max2(7, z) is max2(7, 3) and it returns 7 again.
Thus, the program prints 7.