Advertisement
RvnDrk

Fibonacci Sequence

Apr 12th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. using System;
  2.  
  3. class FibonacciNums
  4. {
  5. static void Main()
  6. {
  7. long N = long.Parse(Console.ReadLine());
  8. Fibonacci(0, 1, 1, N);
  9. }
  10.  
  11. public static void Fibonacci(long a, long b, long counter, long N)
  12. {
  13. if (N >= 1 && N <= 50)
  14. {
  15. if (counter < N)
  16. {
  17. Console.Write(a + ", ");
  18. Fibonacci(b, a + b, counter + 1, N);
  19. }
  20. else if (counter == N)
  21. {
  22. Console.WriteLine(a);
  23. }
  24. }
  25. else
  26. {
  27. return;
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement