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

The Seventh Line

Difficulty: ★ ★ ☆ ☆

For me, the scariest part of learning how to program a computer was file access. The problem was the horrid documentation. It introduced both sequential and random file access together without much explanation. So it was with much trepidation that I wrote my first file I/O program. That’s when I realized that the manual was stupid.
Continue reading