viraco4a

FibonacciRecursion

May 28th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Fibonacci
  6. {
  7. class Program
  8. {
  9.  
  10. static int Fib(int n)
  11. {
  12. if (n == 1 || n == 2)
  13. {
  14. return 1;
  15. }
  16. else
  17. {
  18. return Fib(n - 1) + Fib(n - 2);
  19. }
  20. }
  21.  
  22. static void Main()
  23. {
  24. int n = int.Parse(Console.ReadLine());
  25. int result = Fib(n);
  26. Console.WriteLine(result);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment