pifka

Fibonacci-recursion

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