C++ code to print fibonacci series

This program will print the fibonacci series.

#include
#include
void main()
{
int n,a=0,b=1,c,i;
clrscr();
cout<<"Enter value of n:";
cin>>n;
cout<<"nFibonacci series is:";
for(i=0;i{
if(i<=1)
{
c=i;
}
else
{
c=a+b;
a=b;
b=c;
}
cout<}
getch();
}

Output:

Enter value of n:5
Fibonacci series is: 0 1 1 2 3

Add Comment