Solve problem 12 using C++.