C++20 sections · 1024 units
Open in Course

Problem: Find Maximum

Returning the larger value

Write int max(int a, int b) that returns the larger integer. If a > b, return a, else return b. In main, read two numbers, call max, print result. This is a building block.

You'll use max in sorting, searching, optimization. Take inputs, compare, return result. No printing inside. Test edge cases. Equal numbers? Return either. Negative? Comparison still works.

Simple function, but think through all inputs.