C++ Programming Tutorial

 
 
 
 

Image

 # include <iostream.h>
 # include    <conio.h>

 const long fibonacci(const int);

 int main()
 {
    clrscr( );

    int number;

    cout<<\"\\n Enter the number = \";
    cin>>number;

    cout<<\"\\n\\n The \"<<number<<\"_th term of fibonacci series = \"<<fibonacci(number);

    getch( );
    return 0;
 }


 //----------------------------  fibonacci( )  ---------------------------//


 const long fibonacci(const int n)
 {
    if(n==0 || n==1)
       return n;

    else
    {
       long fn_1=0;
       long fn_2=1;
       long fn;

       for(int count=2;count<=n;count++)
       {
      fn=(fn_1+fn_2);
      fn_1=fn_2;
      fn_2=fn;
       }

       return fn;
    }
 }