Solution in C.