Advertisement
ivan_yosifov

Fibonacci_Recursive

Dec 14th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.43 KB | None | 0 0
  1. // Fibonacci numbers - 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
  2. using System;
  3.  
  4. class Program
  5. {
  6.     static long Fib(int n)
  7.     {
  8.         if (n <= 2)
  9.         {
  10.             return 1;
  11.         }
  12.         return Fib(n - 1) + Fib(n - 2);
  13.     }
  14.     static void Main()
  15.     {
  16.         int element = 10;
  17.         long result = Fib(element);
  18.         Console.WriteLine("The {0} Fibonacci number is {1}", element, result);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement