Page 1 of 1

Square root program

Posted: Mon Jan 11, 2010 3:36 pm
by lrcvs
'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

Posted: Mon Jan 11, 2010 4:47 pm
by Prosper
Why would you write that out in QBASIC? In C++ all you have to do is type "sqrt".

Posted: Mon Jan 11, 2010 5:21 pm
by burger2227
His posts are proliferous and placed at EVERY QB site he has found!

Currently he is polluting the QB64 site also....... :(

Posted: Tue Jan 12, 2010 1:18 am
by lrcvs
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.

:wink: 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:

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

Posted: Tue Jan 12, 2010 2:40 pm
by burger2227
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.

Posted: Tue Jan 12, 2010 3:26 pm
by lrcvs
The old European Union ...

:wink: It's a great salad separate countries ... by a union.