Advertisement
cardel

fibunnaci.cpp

Sep 4th, 2016
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. /*
  2.  * Autor: Carlos Andres Delgado
  3.  * Nombre: fibunacci.cpp
  4.  * Descripción: Soluciona la serie de fibunnaci de forma iterativa
  5.  * Fecha: 02-Septiembre-2016
  6.  */
  7.  
  8.  #include <iostream>
  9.  using namespace std;
  10.  
  11.  int main(){
  12.      
  13.         int faa = 0; //f(0)
  14.         int fa = 1; //f(1)
  15.        
  16.         int f = faa + fa; //f(2)
  17.         cout << "f(0)" << faa << endl;
  18.         cout << "f(1)" << fa << endl;
  19.         cout << "f(2)" << f << endl;
  20.        
  21.         for(int i=3; i<=100; i++){
  22.             faa = fa; // f(i-2)
  23.             fa = f; // f(i-1)
  24.        
  25.             f = faa + fa; //f(i)
  26.             cout << "f(" << i << ") " << f <<endl;
  27.         }
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement