Write a C++ program to print the Fibonacci series 0 1 1 2 3 5 8 13 …. By getting number of number to be displayed is given as input Eg. 5 is input value means it should print first 5 numbers 0 1 1 2 3
Implementation of the above problem:
#include<iostream.h>
int main()
{
int i,j,n,f0,f,f1;
cout<<"\nEnter the value of n\n";
cin>>n;
f0=-1;
f1=1;
i=1;
while(i<=n)
{
f=f0+f1;
cout<<" " <<f;
f0=f1;
f1=f;
i++;
}
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: