Advertisement
Pretoript

fibonacci

Jul 23rd, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int fibonacci(int n)
  4. {
  5.     if(n==1 || n== 2)
  6.         return 1;
  7.  
  8.     return fibonacci(n-2) + fibonacci(n-1);
  9. }
  10.  
  11. int main()
  12. {
  13.  
  14.     for(int i= 1; i<=20; ++i)
  15.     {
  16.         std::cout << "fibonacci(" <<i<<")= "<< fibonacci(i) << std::endl;
  17.     }
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement