Advertisement
shaabash

programowanie 15.12.2018 rekurencje

Dec 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9. class Program
  10. {
  11. //int licz = 0;
  12. //static int fib(int n)
  13. //{
  14.  
  15. // Console.WriteLine(n);
  16. // if (n == 0) return 1;
  17. // if (n == 1) return 1;
  18. // else return fib(n - 1) + fib(n - 2);
  19. //}
  20.  
  21.  
  22. static int dod(int n)
  23. {
  24. if (n < 2) return 1;
  25. else return dod(n - 1) + 1;
  26. }
  27.  
  28.  
  29.  
  30. static void Main(string[] args)
  31. {
  32. int n, w;
  33. Console.WriteLine("Podaj n");
  34. n = int.Parse(Console.ReadLine());
  35. //Console.WriteLine("Fib {0} = {1}", n, fib(n));
  36. Console.WriteLine(dod(n));
  37.  
  38. Console.ReadKey();
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement