Posted By

ldominov on 01/16/13


Tagged


Versions (?)

fibo


 / Published in: C++
 

Fibonacci series implementation in c++ , dynamic programming

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long int fibo(int n){
  6. long prethodni=0, trenutni=1;
  7. if(n == 0) return 0;
  8. else if (n == 1) return 0;
  9. for(int i=1; i<n;i++){
  10. long novi = prethodni + trenutni;
  11. prethodni = trenutni;
  12. trenutni = novi;
  13. }
  14. return trenutni;
  15. }
  16.  
  17. int main(){
  18. cout << "Koji clan fibonaccijevog niza zelite izracunati? ";
  19. int n; cin >> n;
  20. cout << "\nTaj clan iznosi: " << fibo(n) << endl;
  21. cin >> n;
  22. return 0;
  23. }

Report this snippet  

You need to login to post a comment.