54. Sensor Clamp Function Template

Your task is to write a function template named clampValue that:

  • Takes three parameters: val, minVal, and maxVal.
  • Returns minVal if val is less than minVal.
  • Returns maxVal if val is greater than maxVal.
  • Otherwise, returns val.

The program will:

  1. Read min and max values.
  2. Read one value (val).
  3. Print the clamped result.
     

Example

Input:

0 10
5

Output:

Clamped Value: 5

 

Why this output?

  • Since 5 is within [0, 10], it remains unchanged.
     

Question Significance

This problem introduces function templates, which allow a single function to work with multiple types (e.g., int, float).

Loading...

Input

0 10 5

Expected Output

Clamped Value: 5