1

As I am currently learning C#, I made a small program to calculate X amount of fibonacci numbers. However, as the numbers quickly get quite large, not even an unsigned long can hold the numbers. How do I solve this problem? Make my own superlarge integer datatype?

cgt
  • 526
  • 6
  • 18

3 Answers3

5

Are you using .NET4 or newer? If so you could use BigInteger.

LukeH
  • 263,068
  • 57
  • 365
  • 409
  • Thank you. BigInteger works great. Will mark this as the answer when the timer allows me to. – cgt Feb 28 '12 at 11:48
2

No data type will be able to hold all the numbers. There are too many.

The solvability of your problem depends critically on the upper bound you put on X. Depending on which it is, BigInteger can be a possibility, as LukeH says.

Community
  • 1
  • 1
Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
  • 2
    Obviously it cannot store _all_ the numbers as the sequence is infinite. All I want is a lot of them. :D – cgt Feb 28 '12 at 11:40
  • 1
    The Fibonnaci numbers form an infinite countable set, there can never be 'too many'! :D – Shai Feb 28 '12 at 11:40
2

you can do String sum processing for a calculate too many fib number. also can use BigInteger for limited number

Nikson Kanti Paul
  • 3,394
  • 1
  • 35
  • 51