Lesson 61: Clock maths
Esta página necesita un navegador reciente (con soporte para SharedArrayBuffer). Por favor, actualiza Chrome, Edge, Firefox o Safari a la última versión.
English
Whole parts and remainders
- 3725 seconds is not easy to read. 1:02:05 is.
- DIV gives the whole-number part of a division: 3725 DIV 3600 = 1.
- MOD gives the remainder: 3725 MOD 60 = 5.
- In C++,
/on two whole numbers is DIV, and%is MOD.
Words for this lesson
| Word | Meaning |
|---|---|
| DIV | integer division: the whole number of times |
| MOD | the remainder after integer division |
| library routine | a ready-made function of the language |
English
3725 seconds
| Sum | Result | Meaning |
|---|---|---|
| 3725 DIV 3600 | 1 | hours |
| 3725 DIV 60 | 62 | all the minutes |
| 62 MOD 60 | 2 | minutes left after the hours |
| 3725 MOD 60 | 5 | seconds left |
English
In the exam
- 0478/21/M/J/25 Q5: state the purpose of MOD and DIV. Mark scheme: MOD returns the remainder of a division, for example MOD(10, 3); DIV is integer division: it returns the quotient, for example DIV(10, 3).
- 0478/21/M/J/23 Q4: the purpose of DIV and ROUND. Mark scheme: DIV performs integer division and keeps only the whole number part, e.g. DIV(9, 4) = 2; ROUND rounds a value to a given number of decimal places, e.g. ROUND(4.56, 1) = 4.6.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
Type a number of seconds, for example 3725. Finish showTime(s) so it prints hours, minutes and seconds: Time: 1:02:05. Use DIV (whole-number division, / on whole numbers in C++) and MOD (the remainder, %). One hour is 3600 s.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
Now a running clock. It starts at 23:59:57 and adds one second each second. A day has 86 400 seconds, so after 23:59:59 it must start again at 0:00:00. Use MOD to make the count go round.
Haz clic en Ejecutar para ver la salida aquí.