Implementation of ex10.c
malloc version on ex10.c