This is the solution for example 1-13 in the book "The C Programming Language"