Advertisement
bolji_programer

Matematicki algoritmi - Da li je broj Fibonacijev

Jan 28th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool PotpunKvadrat(int x)
  6. {
  7.     int k=sqrt(x);
  8.     if (k*k==x) return true;
  9.     return false;
  10. }
  11.  
  12. bool FibBroj(int n)
  13. {
  14.     if (PotpunKvadrat(5*n*n+4) || PotpunKvadrat(5*n*n-4)) return true;
  15.     return false;
  16. }
  17.  
  18. int main()
  19. {
  20.     int n;
  21.     cin>>n;
  22.  
  23.     if (FibBroj(n)) cout<<"Broj "<<n<<" jeste Fibonacijev broj"<<endl;
  24.     else cout<<"Broj "<<n<<" nije Fibonacijev broj"<<endl;
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement