← Back to Functions/Methods
Question 365
Function: Clamp a Value
Function: Clamp a Value
Write a functionclamp(int x, int lo, int hi)that returnsloifxis below the range,hiifxis above it, andxotherwise. Read a value from input and clamp it to the range10to20. For input5the 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.