Advertisement
Guest User

Untitled

a guest
Jun 14th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace isFibonacciNumber
  4. {
  5. class CheckNumber
  6. {
  7. public bool isPerfectSquare(int x)
  8. {
  9. int s = Convert.ToInt32(Math.Sqrt(x));
  10. return (s * s == x);
  11. }
  12. public bool isFibonacci(int x)
  13. {
  14. return isPerfectSquare(5 * x * x + 4) || isPerfectSquare(5 * x * x - 4);
  15. }
  16. static void Main(string[] args)
  17. {
  18. Console.WriteLine("Провери числа дали са от редицата на Фибоначи ");
  19. bool loop = true;
  20. while (loop)
  21. {
  22. Console.WriteLine();
  23. Console.Write("Въведи число за проверка или 0 за изход: ");
  24. int s = Convert.ToInt32(Console.ReadLine());
  25. if (s != 0)
  26. {
  27. CheckNumber Fi = new CheckNumber();
  28. if (Fi.isFibonacci(s)) { Console.WriteLine(s + " - е Фибоначи"); } else { Console.WriteLine(s + " - не е Фибоначи"); }
  29. }
  30. else { loop = false; }
  31. }
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement