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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: