SEGUNDO PARCIAL

sábado, 19 de noviembre de 2011

CODIGO FIBONACCI

  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. void main()
  5. {
  6.   int a,b,x,c,l;
  7.   a=1; b=1; x=0; c=0;
  8.   cout<<"Introduce el limite de la serie: "; cin>>l;
  9.   if (l>0) {
  10.     if (l==1) cout<<"1"<<endl;
  11.     else
  12.       {
  13.       cout<<endl<<a<<", "<<b<<", ";
  14.       while (c<l-2)
  15.         {
  16.          c++;
  17.          x=a+b;
  18.          cout<<x<<", ";
  19.          a=b;
  20.          b=x;
  21.         }
  22.       }
  23.   }
  24.   system("PAUSE");
  25. }



No hay comentarios:

Publicar un comentario