tasks 6 to 9 from Recursion