Solved Problem 1 in C