basics · beginner · ~15 min

Days in a month

Group switch cases that share a result.

Challenge

Implement int days_in_month(int m) returning the number of days in month m (1-12) for a non-leap year. Return 0 for an invalid month.

Starter code

int days_in_month(int m) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.