Babbage problem: Difference between revisions

(Added Forth)
Line 327:
}</lang>
<pre>25264</pre>
 
=={{header|Liberty BASIC}}==
Now Mr. Babbage -- May I call you Charlie? No. OK -- we'll first start with 'n' equal to zero, then multiply it by itself to square it. If the last six digits of the result are not 269696, we'll add one to 'n' then go back and square it again. On our modern computer it should only take an instant to find the answer...
<lang lb>
' What is the smallest positive integer, n, whose square ends in the digits 269,696?
[start]
if right$(str$(n*n),6)<>"269696" then n=n+1: goto [start]
print "Found it! n = "; n
print "n*n = "; n*n
end
</lang>
Eureka --
<lang sh>
Found it! n = 25264
n*n = 638269696
</lang>
Now my question for you, Sir, is how did you know that the square of ANY number would end in 269696?? If you had been wrong the computer program would still be running!
 
=={{header|PARI/GP}}==
Anonymous user