Advertisement
_liemnguyen

Câu 1

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