Last active
January 6, 2017 05:46
-
-
Save jaccarmac/50fba479b6631c3aee95479fbd666360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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