Solve problem 17 using C++.