Answer to problem 3 in c++

answer to problem 3