Solves Problem 19 in C++