ilmisha

Fibo Numbers

Nov 23rd, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2. class FibonachiNumbers
  3. {
  4. static void Main()
  5. {
  6. int a = 0;
  7. int b = 1;
  8. int firstNum = 0;
  9. int secondNum = 1;
  10.  
  11.  
  12. Console.WriteLine("Insert your num");
  13. int fiboNum = int.Parse(Console.ReadLine());
  14.  
  15. if (fiboNum == 1)
  16. {
  17. Console.WriteLine(firstNum);
  18. }
  19.  
  20. if (fiboNum == 2)
  21. {
  22. Console.Write(firstNum + " " + secondNum);
  23. }
  24. if (fiboNum > 2)
  25. {
  26. Console.Write(a + " " + b + " ");
  27. for (int i = 2; i < fiboNum; i++)
  28. {
  29. int otherNum = firstNum;
  30. firstNum = secondNum;
  31. secondNum = otherNum + secondNum;
  32. Console.Write(secondNum + " ");
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment