Here are two ways to calculate the Fibonacci sequence in C#:
main.cs185 chars12 linesThis method uses recursive calls to calculate the Fibonacci number of n. It's simple to understand, but it can be very slow for large values of n.
main.cs227 chars14 linesThis method uses dynamic programming to calculate the Fibonacci number of n. It's much faster than the recursive method for large values of n. It uses an array to store previously calculated Fibonacci numbers, so that it doesn't have to recalculate them.
gistlibby LogSnag