basics · beginner · ~15 min
Compose comparisons into a clamp.
Implement int clamp(int v, int lo, int hi) returning v constrained to the range [lo, hi].
int clamp(int v, int lo, int hi) {
/* TODO */
return v;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.