{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2.3.maxofthree.gray

# 2.3.maxofthree.gray - if cfw Max Of Three if(i > j cfw Max...

This preview shows pages 1–4. Sign up to view the full content.

32 CSE 201 – Elementary Computer Programming 32 Max Of Three if ( ) { } else { } •We’re going to start with our generic if-else statement. CSE 201 – Elementary Computer Programming 33 Max Of Three if (i > j) { } else // i <= j { } •Now, we need to eliminate one of the variables from our decision. So, we compare the values in i and j . •If i is greater than j : •Then there’s no way j could be our max! •If i is not greater than j : i cannot be the max number.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
34 CSE 201 – Elementary Computer Programming 34 Max Of Three if (i > j) { if (i > k) { } else { } } else // i <= j { } •For now, let’s assume that i > j is true . •Now all we have to do is compare the values in i and k . CSE 201 – Elementary Computer Programming 35 Max Of Three if (i > j) { if (i > k) // i is max { } else // k is max { } } else // i <= j { } •If i is greater than k , then i is the largest number of all three i > j and i > k •Therefore i is our maximum value! •If i is not greater than k , then k is the largest number k >= i and i > j •Therefore, k is the max value.
36 CSE 201 – Elementary Computer Programming 36

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern