Exercise 2-10 of 'The C Programming Language'