implement ex4.c