Advertisement
bolji_programer

Matematicki algoritmi - N-ti Fibonacijev broj (DP)

Jan 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int FibBroj(int n)
  5. {
  6.     int a=0,b=1,c;
  7.  
  8.     if (n==0) return 0;
  9.  
  10.     for (int i=2;i<=n;i++)
  11.     {
  12.         c=a+b;
  13.         a=b;
  14.         b=c;
  15.     }
  16.  
  17.     return b;
  18. }
  19.  
  20. int main()
  21. {
  22.     int n;
  23.     cin>>n;
  24.  
  25.     cout<<FibBroj(n)<<endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement