neogz

Fibonacci rekurzija

Apr 1st, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int f(int n)
  5. {
  6.     if (n <= 2)return 1;
  7.     else return (f(n-1) + f(n-2));
  8.    
  9. }
  10.  
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cout << "Unesi n: ";
  16.     cin >> n;
  17.  
  18.     cout << "Fibonacci od n = " << f(n);
  19.  
  20.     system("pause >nul");
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment