This little Fortran program, originally written in DOS, uses the arithmetic sequence x_n+1={1/2} x_{n} + A / x_{n} to find the root of A.

All you have to do is to enter A and a guess value x_0

Caution: This program is very old; it uses Escape codes to clear the screen. In DOS, it needs the ANSI.COM driver. I haven’t test it on Linux 😉

        DIMENSION X(0:100)
        REAL A,B
        INTEGER I,J,K,L
        CHARACTER ESC
 
        ESC=CHAR(27)
        N=0
        B=.000001
 
        WRITE (*,1)  ESC
1       FORMAT (1X,A,'[2J')
 
        WRITE (*,2) ESC,ESC
2       FORMAT (1X,A,'[5B',A,'[3C','FINDS THE sqrt OF A GIVEN NUMBER
     B USING ARITHMETIC ANALYSIS Xn=0.5*(Xn+A/XN)')
 
        WRITE (*,3) ESC,ESC
3       FORMAT (1X,A,'[2B',A,'[2C','ENTER NUMBER A:')
        READ (*,*) A
 
        WRITE (*,4) ESC,ESC
4       FORMAT (1X,A,'[1B',A,'[5C','NOW ENTER X0:')
        READ (*,*) X(0)
 
        DO 10 I=1,20
 
        X(N+1)=.5*(X(N)+A/X(N))
 
        N=N+1
 
        IF (ABS(X(N+1)-X(N)).LT.B) GOTO 11
 
10      CONTINUE
 
 
11      WRITE (*,15) ESC,ESC,X(N),N
15      FORMAT (1X,A,'[2B',A,'[1C','THE SQRT(A) IS:',F10.5,2X,
     B 'IN',1X,I2,1X,'REPEATS')
 
        STOP
        END