SHARE
TWEET

Câu 1

_liemnguyen Feb 14th, 2020 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top