Westonci.ca offers fast, accurate answers to your questions. Join our community and get the insights you need now. Get expert answers to your questions quickly and accurately from our dedicated community of professionals. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

1 #include 2 3 int max2(int x, int y) { 4 int result = y; 5 if (x > y) { 6 result = x; 7 } 8 return result; 9 } 10 11 int max3(int x, int y, int z) { 12 return max2(max2(x,y),z); 13 } 14 15 int main() { 16 int a = 5, b = 7, c = 3; 17 18 printf("%d\n",max3(a, b, c)); 19 20 printf("\n\n"); 21 return 0; 22 } What number is printed when the program is run?

Sagot :

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.