Problem 2 in c and problem 1 in c++