k&r; exercise 1.12 - improve solution