Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/Babbage-problem/FreeBASIC/babbage-problem.basic
Normal file
42
Task/Babbage-problem/FreeBASIC/babbage-problem.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue