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

In C write a mathematical operation: max (v, w, x, y, z) as a single statement u

ID: 3916106 • Letter: I

Question

In C write a mathematical operation: max (v, w, x, y, z) as a single statement using the conditional expression operator.

For example, max (x, y) would be: max = (x > y) ? x : y;

Hint: You will have more than one conditional expression operator (?) in your answer, and it would help to use Boolean logic operations.

I have been struggling with the logic on this i can get a Three numbers but not five max = v > w ? (v > x ? v : x) : (w > x ? w : x); and i am unsure where the boolean condition(s) would fit in.

thanks!

Explanation / Answer

max = v > w ? (v>x ? (v>y ? ( v>z ? v : z) : (y>z ? y:z ) ) : (x>y ? (x>z ? x:z):(y>z ? y:z)) ) : (w>x ? (w>y ? ( w>z ? w : z) : (y>z ? y:z ) ) : (x>y ? (x>z ? x:z):(y>z ? y:z)));

I have run this code and this is working fine.
Tip: whenever you want to make these type of code try to solve only one part like in this question, for v>w we write code before ":" and for the situation to be false just exchange w with v.

and always try to divide this type of long code into smaller parts and surely you will get your answer correct.

If you have any problem with this code also, you can leave the comment in the comment section.