Ex3.5 finished

works for all numerical cases