Program for FIBONACCI SERIES in C++.

#include<iostream.h>        //Including header files

int fibnac(int n);            //function prototype for fibnac series

void main()
int n,i;
char ch;

//Taking the no. of terms to be found out

cout<<"How many terms of Fibonacci Series do you wanna calculate\n";

for(i=1;i<=n;i++)        //Calculating the terms one-by-one and writing to the VDU
int p=fibnac(i);
cout<<p<<"   ";

cout<<"Do you wanna continue?(Y/N)\t";


int fibnac(int p)            //Function to calculate a particular fibonacci term
if (p==1)  return(1);
if (p==2)  return(2);
if(p>2)    return(fibnac(p-1)+fibnac(p-2));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s