Skip to content

Instantly share code, notes, and snippets.

@jaccarmac
Last active January 6, 2017 05:46
Show Gist options
  • Save jaccarmac/50fba479b6631c3aee95479fbd666360 to your computer and use it in GitHub Desktop.
Save jaccarmac/50fba479b6631c3aee95479fbd666360 to your computer and use it in GitHub Desktop.
program nSquareRoots
parameter (n = 100)
real, dimension (n) :: squares, squareRoots
squares = (/ (i, i = 1, n) /)
squareRoots = (/ (customSqrt(squares(i), 0.001), i = 1, n) /)
Print *, "Squares:"
Print *, squares
Print *, "Square roots:"
Print *, squareRoots
end program nSquareRoots
real function customSqrt(a, e)
x = 0.5 * a
y = (x*x + a)/(2*x)
do while (abs(x - y) > e)
x = y
y = (x*x + a)/(2*x)
end do
customSqrt = y
return
end function customSqrt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment