basics · beginner · ~15 min
Reason about the range of a fixed-width type.
Check whether an integer fits in an unsigned 8-bit value.
Implement int fits_in_uint8(int n) that returns 1 if n is in the range 0..255 (the full range of a uint8_t), else 0. No main — the grader calls it.
A single int n (may be negative or larger than 255).
Returns 1 if 0 <= n <= 255, otherwise 0.
fits_in_uint8(0) -> 1
fits_in_uint8(255) -> 1
fits_in_uint8(256) -> 0
fits_in_uint8(-1) -> 0
A single int n.
1 if 0 <= n <= 255, otherwise 0.
int fits_in_uint8(int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.