Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Program is in C* Write if-else statements to find the maximum of 6 numbers a, b

ID: 3797565 • Letter: #

Question

*Program is in C*

Write if-else statements to find the maximum of 6 numbers a, b, c, d, e and f. You can assume that all the numbers are distinct and you can use any number of additional variables. Do not use any functions to compute the maximum. Just use if-else statements. Try to minimize the amount of code that needs to be written. Assume that the following function is available. int max3(int x, int y, int z) Assume that all the numbers are distinct and show how to use this method to compute the following maximum of 2 numbers a and b maximum of 4 numbers a, b, c and d minimum of 3 numbers a, b and c

Explanation / Answer


int a, b, c, d, e, f;

int max = a; // initializing max with a
if(max < b)
   max = b;
if(max < c)
   max = c;
if(max < d)
   max = d;
if(max < e)
   max = e
if(max < f)
   max = f;

int max3(int x, int y, int z);

a) Maximum of a, b

   max = max3(a, b, b);

b) Maximum of a, b, c, d
   int max1 = max3(a,b,c);
   int max = max3(max1, d, d);

c) Maximum of a,b,c
   int max = max3(a, b, c);