Isqrt (integer square root) of X: Difference between revisions
Content added Content deleted
(Isqrt (integer square root) of X in BASIC256) |
(Isqrt (integer square root) of X in yABASIC) |
||
Line 6,504: | Line 6,504: | ||
73 49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407 7,015,820,362,023,593,956,150,476,655,802 |
73 49,221,735,352,184,872,959,961,855,190,338,177,606,846,542,622,561,400,857,262,407 7,015,820,362,023,593,956,150,476,655,802 |
||
</pre> |
</pre> |
||
=={{header|Yabasic}}== |
|||
<lang freebasic>// Rosetta Code problem: https://rosettacode.org/wiki/Isqrt_(integer_square_root)_of_X |
|||
// by Jjuanhdez, 06/2022 |
|||
print "Integer square root of first 65 numbers:" |
|||
for n = 1 to 65 |
|||
print isqrt(n) using("##"); |
|||
next n |
|||
print : print |
|||
print "Integer square root of odd powers of 7" |
|||
print " n | 7^n | isqrt " |
|||
print "----|--------------------|-----------" |
|||
for n = 1 to 21 step 2 |
|||
pow7 = 7 ^ n |
|||
print n using("###"), " | ", left$(str$(pow7,"%20.1f"),18), " | ", left$(str$(isqrt(pow7),"%11.1f"),9) |
|||
next n |
|||
end |
|||
sub isqrt(x) |
|||
q = 1 |
|||
while q <= x |
|||
q = q * 4 |
|||
wend |
|||
r = 0 |
|||
while q > 1 |
|||
q = q / 4 |
|||
t = x - r - q |
|||
r = r / 2 |
|||
if t >= 0 then |
|||
x = t |
|||
r = r + q |
|||
end if |
|||
wend |
|||
return int(r) |
|||
end sub</lang> |