I need help with Fibonacci sequence working with big numbers

I would like to write the numbers of the Fibonacci sequence, until it's 2000 characters long. So I use the following method to add the numbers. I have the problems at jumping to the next number.

static void Main(string[] args) { var carry = false; var result = String.Empty; List<string> numbers=new List<string>(); numbers.Add("1"); numbers.Add("1"); int count = 2; int k=0; while(result.Length<2000){ for (int i = numbers[count-1].Length - 1; i >= 0; i--) { var augend = Convert.ToInt32(numbers[k].Substring(i, 1)); var addend = Convert.ToInt32(numbers[k+1].Substring(i, 1)); var sum = augend + addend; sum += (carry ? 1 : 0); carry = false; if (sum > 9) { carry = true; sum -= 10; } result = sum.ToString() + result; } if (carry) { result = "1" + result; } numbers.Add(result); count++; k++; } 

by DinterRM via /r/csharp

Leave a Reply