solved ex5.3.5
use function