C Created: Joe Zachary, October 26, 1992 C Modified: C This function takes a real number "X" as an argument and computes C its square root using an approximation algorithm. REAL FUNCTION SROOT (X, COUNT) IMPLICIT NONE REAL X, GUESS INTEGER COUNT, I GUESS = 1 DO I = 1, COUNT GUESS = (GUESS + X/GUESS) / 2 ENDDO SROOT = GUESS RETURN END C This program tests out the SROOT function. It also prints out C the result of the intrinsic SQRT function for comparison. PROGRAM SRTEST IMPLICIT NONE REAL Y, SROOT INTEGER N PRINT *, 'Enter a real number' READ *, Y PRINT *, 'Enter an integer' READ *, N PRINT *, 'The approximate square root of ', + Y, ' is ', SROOT(Y, N) PRINT *, 'Fortran''s approximation is ', SQRT(Y) STOP END