Babbage problem: Difference between revisions
added FreeBASIC
(Wrote a babbage number code in R lang) |
(added FreeBASIC) |
||
Line 346:
<pre>25264</pre>
=={{header|FreeBASIC}}==
<lang freebasic>' version 25-10-2016
' compile with: fbc -s console
' Charles Babbage would have known that only number ending
' on a 4 or 6 could produce a square ending on a 6
' also any number below 520 would produce a square smaller than 269,696
' we can stop when we have reached 99,736
' we know it square and it ends on 269,696
Dim As ULong number = 524 ' first number to try
Dim As ULong square, count
Do
' square the number
square = number * number
' look at the last 6 digits, if they match print the number
If Right(Str(square), 6) = "269696" Then Exit Do
' increase the number with 2, number end ons a 6
number = number +2
' if the number = 99736 then we haved found a smaller number, so stop
If number = 99736 Then Exit Do
square = number * number
' look at the last 6 digits, if they match print the number
If Right(Str(square),6 ) = "269696" Then Exit Do
' increase the number with 8, number ends on a 4
number = number +8
' go to the first line under "Do"
Loop
If number = 99736 Then
Print "No smaller number was found"
Else
' we found a smaller number, print the number and its square
Print Using "The number = #####, and its square = ##########,"; number; square
End If
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</lang>▼
{{out}}
<pre>The number = 25,264 and its square = 638,269,696</pre>
=={{header|FutureBasic}}==
<lang qbasic>include "ConsoleWindow"▼
▲include "ConsoleWindow"
dim as long i
Line 357 ⟶ 401:
print "The smallest number whose square ends in 269696 is"; i
print "Its square is"; i ^ 2</lang>
{{out}}
▲</lang>
<pre>The smallest number whose square ends in 269696 is 25264▼
Its square is 638269696</pre>▼
▲The smallest number whose square ends in 269696 is 25264
▲Its square is 638269696
=={{header|Haskell}}==
|