Completed problem 5 in C, some minor cleanup