Problem 1 from 52 programming problems book

 

http://ideone.com/ItvUGS