Solution to problem4.c