### Square root program

Posted:

**Mon Jan 11, 2010 3:36 pm**'Program square root

'lrcvs

'12 Jan 2010

'This program is based on the algorithm of arithmetic division program.

cls

'a$ = number to square root

a$ = "25521342100008787"

la = INT(LEN(a$) / 2) + 1

c$ = STRING$(la, "0")

FOR r = 1 TO la

FOR s = 0 TO 9

MID$(c$, r) = LTRIM$(STR$(s))

v$ = LTRIM$(STR$(VAL(c$) * VAL(c$)))

'IF VAL(v$) = VAL(a$) THEN PRINT v$

IF VAL(a$) > VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s))

IF VAL(a$) < VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s - 1)): EXIT FOR

NEXT s

NEXT r

t$ = LTRIM$(STR$(VAL(a$) - (VAL(c$) * VAL(c$))))

d$ = LTRIM$(STR$(VAL(t$) / (VAL(c$)) / 2))

PRINT "Square root of = "; a$

PRINT

PRINT "Program = "; LTRIM$(STR$(VAL(c$))) + " . " + RIGHT$(d$, LEN(d$) - 1)

PRINT

PRINT "Remanence = "; t$

PRINT

PRINT "Computer = "; SQR(VAL(a$))

SLEEP

END

'lrcvs

'12 Jan 2010

'This program is based on the algorithm of arithmetic division program.

cls

'a$ = number to square root

a$ = "25521342100008787"

la = INT(LEN(a$) / 2) + 1

c$ = STRING$(la, "0")

FOR r = 1 TO la

FOR s = 0 TO 9

MID$(c$, r) = LTRIM$(STR$(s))

v$ = LTRIM$(STR$(VAL(c$) * VAL(c$)))

'IF VAL(v$) = VAL(a$) THEN PRINT v$

IF VAL(a$) > VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s))

IF VAL(a$) < VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s - 1)): EXIT FOR

NEXT s

NEXT r

t$ = LTRIM$(STR$(VAL(a$) - (VAL(c$) * VAL(c$))))

d$ = LTRIM$(STR$(VAL(t$) / (VAL(c$)) / 2))

PRINT "Square root of = "; a$

PRINT "Program = "; LTRIM$(STR$(VAL(c$))) + " . " + RIGHT$(d$, LEN(d$) - 1)

PRINT "Remanence = "; t$

PRINT "Computer = "; SQR(VAL(a$))

SLEEP

END