Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
83
Task/Fibonacci-sequence/FreeBASIC/fibonacci-sequence.basic
Normal file
83
Task/Fibonacci-sequence/FreeBASIC/fibonacci-sequence.basic
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
'Fibonacci extended
|
||||
'Freebasic version 24 Windows
|
||||
Dim Shared ADDQmod(0 To 19) As Ubyte
|
||||
Dim Shared ADDbool(0 To 19) As Ubyte
|
||||
|
||||
For z As Integer=0 To 19
|
||||
ADDQmod(z)=(z Mod 10+48)
|
||||
ADDbool(z)=(-(10<=z))
|
||||
Next z
|
||||
|
||||
Function plusINT(NUM1 As String,NUM2 As String) As String
|
||||
Dim As Byte flag
|
||||
#macro finish()
|
||||
three=Ltrim(three,"0")
|
||||
If three="" Then Return "0"
|
||||
If flag=1 Then Swap NUM2,NUM1
|
||||
Return three
|
||||
Exit Function
|
||||
#endmacro
|
||||
var lenf=Len(NUM1)
|
||||
var lens=Len(NUM2)
|
||||
If lens>lenf Then
|
||||
Swap NUM2,NUM1
|
||||
Swap lens,lenf
|
||||
flag=1
|
||||
End If
|
||||
|
||||
var diff=lenf-lens-Sgn(lenf-lens)
|
||||
var three="0"+NUM1
|
||||
var two=String(lenf-lens,"0")+NUM2
|
||||
Dim As Integer n2
|
||||
Dim As Ubyte addup,addcarry
|
||||
|
||||
addcarry=0
|
||||
|
||||
For n2=lenf-1 To diff Step -1
|
||||
addup=two[n2]+NUM1[n2]-96
|
||||
three[n2+1]=addQmod(addup+addcarry)
|
||||
addcarry=addbool(addup+addcarry)
|
||||
Next n2
|
||||
If addcarry=0 Then
|
||||
finish()
|
||||
End If
|
||||
If n2=-1 Then
|
||||
three[0]=addcarry+48
|
||||
finish()
|
||||
End If
|
||||
|
||||
For n2=n2 To 0 Step -1
|
||||
addup=two[n2]+NUM1[n2]-96
|
||||
three[n2+1]=addQmod(addup+addcarry)
|
||||
addcarry=addbool(addup+addcarry)
|
||||
Next n2
|
||||
three[0]=addcarry+48
|
||||
finish()
|
||||
End Function
|
||||
|
||||
Function fibonacci(n As Integer) As String
|
||||
Dim As String sl,l,term
|
||||
sl="0": l="1"
|
||||
If n=1 Then Return "0"
|
||||
If n=2 Then Return "1"
|
||||
n=n-2
|
||||
For x As Integer= 1 To n
|
||||
term=plusINT(l,sl)
|
||||
sl=l
|
||||
l=term
|
||||
Next x
|
||||
Function =term
|
||||
End Function
|
||||
|
||||
'============== EXAMPLE ===============
|
||||
print "THE SEQUENCE TO 10:"
|
||||
print
|
||||
For n As Integer=1 To 10
|
||||
Print "term";n;": "; fibonacci(n)
|
||||
Next n
|
||||
print
|
||||
print "Selected Fibonacci number"
|
||||
print "Fibonacci 500"
|
||||
print
|
||||
print fibonacci(500)
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue