Added solution to problem 2 in C and C++