Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Fibonacci
- {
- class Program
- {
- static int[] numbers;
- static int Fib(int n)
- {
- if (numbers[n] != 0)
- {
- return numbers[n];
- }
- if (n == 1 || n == 2)
- {
- return 1;
- }
- var result = Fib(n - 1) + Fib(n - 2);
- numbers[n] = result;
- return result;
- }
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- numbers = new int[n + 1];
- int result = Fib(n);
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement