hw4.c implemented