adding solution to the second problem in fortran