Solve problem 30 using C++.