Function: Clamp a Value
mediumQuestion 365Write a function clamp(int x, int lo, int hi) that returns lo if x is below the range, hi if x is above it, and x otherwise. Read a value from input and clamp it to the range 10 to 20. For input 5 the output is exactly what is shown in Expected Output.
Print the clamped value with %d.
Expected output
10= newline. No newline after the last line.
Hints3 available
Sign in to use hintsTopics
Functions/Methods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.