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?

Answers

Answer 1

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.


Related Questions

How many different values can a bit have?
16
2
4.
8

Answers

Answer:

A bit can only have 2 values

Other Questions
PLS HELP!!! Graph the image above after a translation of 5 units right and 3 units down. What type of signal word is used in the sentence?a. generalizationb. descriptionc. thoughtd. feeling X^2-16/x^2-3x-4 simply Can someone please help me A pablo le gust la leyenda sobre i need help asap 1/2k=20 Evaluate the expression for the value given.6a4a; when a = 2 x + 2/3 = -4 one step equation What is the equation of the line that passes through the point (-6, -6) and has aslope of - 1/3 free feet pic clickbait if u answer w full explimation last question on my test! please show some sort of work so i know its correct :) thanks! - dusty. The perimeter of the rectangle is 40 centimeters. Find the value of x.There is a picture of a rectangle and it has an x on the left side and a 3x on the bottom. a. 4b. 5c. 8d. 10 Select the correct answer.Lily feels tired and weak in the evenings after work. Before starting her chores, she eats dinner. Which characteristic of life does Lily exhibit?A. growthB. need for energyC. organizationD. regulation How many triangles do you see? A candy bar costs $0.79Find the price of the candy bar if it is sold with a 65% mark upA. $1.58B. $1.44C. $1.30D. $1.17 Which currency is used in the United States? 4. On a 3-hour trip, a car travels 156 miles.What is the average speed of the car on thistrip? The hierarchy of traits is a structured progression of personality that begins with a few higher-order traits that result inseveral lower-order traits, determining a person's response in a specific situation.Please select the best answer from the choices providedOTOF What is considered a vigorous physical activity?surfingplaying doubles tennischopping wooddancing What are the SIX contrapuntal devices used in the FUGUE?