limun11

PRII - Fibonacci - rekurzija

Mar 20th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fibonaci(int broj)
  5. {
  6.     if (broj <= 1)
  7.         return 1;
  8.     else
  9.         return fibonaci(broj - 1) + fibonaci(broj - 2);
  10. }
  11. void main()
  12. {
  13.     int broj;
  14.     cout << "Unesite broj clanova niza: ";
  15.     cin >> broj;
  16.  
  17.     cout << "Fibonacijev niz je: " << fibonaci(broj) << endl;
  18.     system("PAUSE");
  19. }
Advertisement
Add Comment
Please, Sign In to add comment