hw5 added code for ex3.