Time in seconds
Combine several values into one total. An easy embedded C problem (Variables and operators), run and graded in the browser.
easy · Variables and operators · arithmetic · variables
A real-time clock reports hours, minutes and seconds separately. Timers want a single number.
Return the total number of seconds in h hours, m minutes and s seconds.
Starter code
int seconds_total(int h, int m, int s) {
return 0;
}Example tests
One of each
printf("%d\n", seconds_total(1, 1, 1));Expected output:
3661Minutes and seconds only
printf("%d\n", seconds_total(0, 2, 30));Expected output:
150Learn it first
- Variables and operators · Storing values, doing arithmetic, comparing, and the two surprises of integer maths.
More Variables and operators problems
- Average of three · Add three values and divide.
- Last digit · Use the remainder operator.
- Celsius to Fahrenheit · Fix a formula that divides too early.
- Even or odd · Produce a yes-or-no answer as 1 or 0.
- Operator precedence · Fix an expression that is evaluated in the wrong order.
- Percentage · Keep precision by ordering the operations correctly.
- Does it fit in a byte? · Combine two comparisons with a logical operator.