0

If you are browsing this forum, it is a safe assumption to believe you know of the Fibonacci Series.

After having a couple of minutes, and some random thoughts, I put together a little piece of code that will print this series out to a file.

Private Sub FibWrite(ByVal iMax As Int64)
    Dim sw As New StreamWriter("Path")
    Dim n0 As Int64 = 0
    Dim n1 As Int64 = 1

    Try
        For i = 0 To iMax
            Dim iTemp As Int64 = n1
            n1 = n1 + n0
            n0 = iTemp
            sw.WriteLine(n1)
        Next
    Catch ex As Exception
        MsgBox(ex.ToString)
        sw.WriteLine(ex.Message)
    Finally
        sw.Close()
        sw.Dispose()
    End Try
End Sub

I reached a total of 90 iterations before overflow occurs.

Let's have some fun with this, shall we?

Attachments
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
5702887
9227465
14930352
24157817
39088169
63245986
102334155
165580141
267914296
433494437
701408733
1134903170
1836311903
2971215073
4807526976
7778742049
12586269025
20365011074
32951280099
53316291173
86267571272
139583862445
225851433717
365435296162
591286729879
956722026041
1548008755920
2504730781961
4052739537881
6557470319842
10610209857723
17167680177565
27777890035288
44945570212853
72723460248141
117669030460994
190392490709135
308061521170129
498454011879264
806515533049393
1304969544928657
2111485077978050
3416454622906707
5527939700884757
8944394323791464
14472334024676221
23416728348467685
37889062373143906
61305790721611591
99194853094755497
160500643816367088
259695496911122585
420196140727489673
679891637638612258
1100087778366101931
1779979416004714189
2880067194370816120
4660046610375530309
7540113804746346429
2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by Reverend Jim
1

If you use BigInteger as in

Private Sub FibWrite()

    Dim sw As New System.IO.StreamWriter("d:\temp\fib.txt")

    Dim n0 As BigInteger = 0
    Dim n1 As BigInteger = 1

    Try
        For i = 1 To 1000
            Dim iTemp As BigInteger = n1
            n1 = n1 + n0
            n0 = iTemp
            sw.WriteLine(n1)
        Next
    Catch ex As Exception
        Debug.WriteLine(ex.Message)
        sw.Close()
    End Try

    sw.Close()

End Sub

The 1000th number in the sequence is

70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501

And the 10000th number is

54438373113565281338734260993750380135389184554695967026247715841208582865622349017083051547938960541173822675978026317384359584751116241439174702642959169925586334117906063048089793531476108466259072759367899150677960088306597966641965824937721800381441158841042480997984696487375337180028163763317781927941101369262750979509800713596718023814710669912644214775254478587674568963808002962265133111359929762726679441400101575800043510777465935805362502461707918059226414679005690752321895868142367849593880756423483754386342639635970733756260098962462668746112041739819404875062443709868654315626847186195620146126642232711815040367018825205314845875817193533529827837800351902529239517836689467661917953884712441028463935449484614450778762529520961887597272889220768537396475869543159172434537193611263743926337313005896167248051737986306368115003088396749587102619524631352447499505204198305187168321623283859794627245919771454628218399695789223798912199431775469705216131081096559950638297261253848242007897109054754028438149611930465061866170122983288964352733750792786069444761853525144421077928045979904561298129423809156055033032338919609162236698759922782923191896688017718575555520994653320128446502371153715141749290913104897203455577507196645425232862022019506091483585223882711016708433051169942115775151255510251655931888164048344129557038825477521111577395780115868397072602565614824956460538700280331311861485399805397031555727529693399586079850381581446276433858828529535803424850845426446471681531001533180479567436396815653326152509571127480411928196022148849148284389124178520174507305538928717857923509417743383331506898239354421988805429332440371194867215543576548565499134519271098919802665184564927827827212957649240235507595558205647569365394873317659000206373126570643509709482649710038733517477713403319028105575667931789470024118803094604034362953471997461392274791549730356412633074230824051999996101549784667340458326852960388301120765629245998136251652347093963049734046445106365304163630823669242257761468288461791843224793434406079917883360676846711185597501

Edited by Reverend Jim

Votes + Comments
Very nice :D
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.