program newt2 c integer out real x external sqr2 common /inout/ out c out = 6 write(out,*) ' newton-s method' 10 write(out,103) read(*, 104) x if (x .lt. -19.0) goto 99 call newton(x, sqr2) write(out, 102) x goto 10 99 stop 102 format(/' the square root of 2 is ', f8.5) 103 format(' first guess? ' ) 104 format(e10.0) end subroutine sqr2(x, fx, dfx) c c -- the square root of 2 c real x, fx, dfx c fx = x * x - 2 dfx = 2 * x return end subroutine newton(x, func) c c -- the solution of f(x) = 0 by newton-s method c integer out real x, fx, dfx, x1, dx, tol common /inout/ out data tol/1.0e-6/ c write(out, 101) 10 x1 = x call func(x, fx, dfx) dx = fx / dfx x = x1 - dx write(out, 102) x1, fx, dfx if (abs(dx) .gt. abs(x * tol)) goto 10 return 101 format(' x fx dfx') 102 format(1x, 0pf13.5, 3x, 1p2e12.4) end