k&r; exercise 1.4 - rewrite with tests and c99 for loop