viraco4a

FibonacciIteration

May 28th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Fibonacci
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. long[] fib = new long[n + 1];
  11. fib[0] = 0;
  12. fib[1] = 1;
  13. fib[2] = 1;
  14. for (int i = 3; i <= n; i++)
  15. {
  16. fib[i] = fib[i - 1] + fib[i - 2];
  17. }
  18. Console.WriteLine(fib[n]);
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment