Open Means Open Means
Inlcude required header files
#include<iostream.h>
#include<conio.h>
Function Declaration
void fibonacci(long int i,long int j);
Instance Variables Declaration
static int totNum;
static int count;
Main Method which uses the recursive function to print fibonacci series
void main(){

Local variables declaration

long int i=0,j=1;
clrscr();

Accept the max number of series

cout<<"Enter The Limit:";
cin>>totNum;

Print initial numbers

cout<<endl<<i<<" "<<j<<" "; 

Track count, initialize to 2, as the starting two numbers are already printed.

count=2;

Recurse through function to print series

fibonacci(i, j);
getch();
}

Now the actual funtionality to get the fibonacci number reccursively.

void fibonacci(long int i,long int j){
// Print next number
cout<<i+j<<" ";

// Increase the count
count++;

Check if count reaches the max number else recurse.

 if(count<=totNum){
fibonacci(j,i+j);
}
}

No comments

Login to post a comment

Show
  • Create an account
  • Forgot your username?
  • Forgot your password?

Related Articles

  • Shell Script to demonstrate functions
  • Know When Do You Have To Sell Your Mutual Funds
  • Getting started with investing in Mutual Funds
  • Credit Cards - Points to remember
  • HTML Basics - Formatting Tags
  • Java Puzzle - Problem of Two Developers
  • Java Puzzle - Problem of Two Developers Part 2
  • Investing Styles
  • Most Dangerous Computer Viruses of the Century
  • Recession Proof Your Career
  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions