Advertisement
neogz

REK - Fibonacci niz

Aug 20th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. /*
  2.     Fibonacci broj.
  3. */
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int rfib (int broj)
  9. {
  10.     if (broj <= 2 && broj >0) return 1;
  11.     if (broj == 0) return 0;
  12.     return rfib(broj - 1) + rfib(broj - 2);
  13. }
  14.  
  15. int main(){
  16.  
  17.     int broj;
  18.     cout << "Unesite 1 broj: ";
  19.     cin >> broj;
  20.  
  21.     cout << "Fibonaci broj od: " << broj << " je " << rfib(broj) << endl;
  22.    
  23.     system("pause>null");
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement