networking · beginner · ~15 min
Bucket a status into its class.
Bucket an HTTP status code into its class by taking its leading digit.
Implement int status_class(int code).
code: an HTTP status code.Return the leading digit (code / 100) for codes in 100..599. Return 0 for any code outside that range.
status_class(200) -> 2 (success)
status_class(404) -> 4 (client error)
status_class(503) -> 5 (server error)
status_class(99) -> 0 (out of range)
code: an HTTP status code.
The leading digit (code/100) for codes in 100..599; 0 otherwise.
Only codes in 100..599 are valid; everything else returns 0.
int status_class(int code) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.