Header Ad

C++ program to display the Fibonacci series using function

In this post, we will write a C++ program to display the Fibonacci series using the function.

C++ program to display the Fibonacci series using function


C++ program to display the Fibonacci series using function.

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

int fib(int);

int main()
{
    system("cls");

    int n;
    std::cout<<"Enter the number you want to series ";
    std::cin>>n;
    std::cout<<"0"<<"\t";

    fib(n);

    getch();
    return 0;
}

int fib(int n)
{
    double c,d,i,e;
    c = 1;
    d = 0;

    for(i=1;i<=n;i++)
    {
        e = c+d;
        c = d;
        d = e;

        std::cout<<e<<"\t";
    }
}



Output

Enter the number you want to series = 10
0 1 1 2 3 5 8 13 21 34 55

Post a Comment

0 Comments