k&r; exercise 1.11 - add boundary conditions