/*
Fibonacci Series: 0 1 1 2 3 5 8....
*/
/*
Imp Test: N is a Fibonacci number if and only if
5 N^2 + 4
or 5N^2 – 4
is a square number.*/
#include <iostream>
using namespace std;
void fib(int n)
{
int prev=0;
int curr = 1;
int next;
for (int i=0;i<n;i++)
{
if(i<=1)
next = i;
else
{
next = prev+curr;
prev = curr;
curr= next;
}
cout<<next<<"\t";
}
}
int main()
{
int n;
cout<<"How many fib ? ";
cin>>n;
fib(n);
return 0;
}
//shorter version of Fibonacci series
void fib(int n)
{
int a,b,c,i;
for(a=0,b=1,c=0,i=0;i<n;c=a+b,a=b,b=c,i++) cout<<c<<"\t";
}