## Square root program

Announce and discuss the progress of your various programming-related projects...programs, games, websites, tutorials, libraries...anything!

Moderators: Pete, Mods

lrcvs
Veteran
Posts: 58
Joined: Mon Mar 10, 2008 9:28 am

### Square root program

'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

Prosper
Newbie
Posts: 7
Joined: Thu Jan 07, 2010 5:29 pm
Why would you write that out in QBASIC? In C++ all you have to do is type "sqrt".

burger2227
Veteran
Posts: 2443
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
His posts are proliferous and placed at EVERY QB site he has found!

Currently he is polluting the QB64 site also.......
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

lrcvs
Veteran
Posts: 58
Joined: Mon Mar 10, 2008 9:28 am
Clippy:

(LOL) A post without your opinion, has less category.!

I think that my experiments are simple, useful.

Also some people are curious mathematical experiments.

In a way is good, both have many fans ...

The write post in QB64, is that QB64 will be a great dialect of Basic, It has a great future!!!!

:::::::::::::::::::::::::::::::::::::::::::

Prosper:

Thanks for your opinion, but I only know Qbasic.

Basic also has SQR (x)

(I'm old school, also I'm very old)

The Germans say:

Why make things easier when you can make it with difficult!

burger2227
Veteran
Posts: 2443
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
No German EVER said that!

They may have said: "Hey this is a nice country, let's take it over!"

The wimpy French said: "Come right in..."

Note that the Germans never even wanted Spain because all they knew was QB.

I love those Europeans with their Euros.