Friday, September 2, 2016

Tags

PROGRAM TO PRINT FIBONACI SERIES UPTO GIVEN NO OF TERMS:
#include<iostream>
using namespace std;
main()
{
int a=0,b=1,n,next;
cout<<"ENTER THE NO OF TERMS";
cin>>n;
if(n==1)
cout<<a;
else if(n<1)
cout<<"PLEASE ENTER VALID NO OF TERMS";
else if(n==2)
cout<<a<<" "<<b;
else
{cout<<a<<" "<<b;
for(int i=3;i<=n;i++)
{
next=a+b;
cout<<" "<<next;
a=b;
b=next;
}

}

}