Completed Ex3 with exception of recursion