Emulating the Modulus Operator

Difficulty: ★ ★ ☆ ☆

I think any kid learning math in school knows what a remainder is, but few understand (or are taught) what a modulus is. It obtains the remainder of one value divided by another, specifically a larger value divided by a smaller value. In C programming, the % (modulo) operator performs this calculation. But what if the C language lacked a modulo operator?
Continue reading

The Double Factorial

Difficulty: ★ ★ ☆ ☆

It’s common in programming to use a factorial as a way to teach about recursion. For example, 5! (five factorial) is 5×4×3×2×1, which is 120. Calculating this result can be done with a recursive function, which is practical and satisfying. But mathematicians have a twisted sense of humor, so they invented something called a double factorial.
Continue reading