Updated problem2.c to make it cleaner