Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence.

Recursive function first 25 numbers of a Fibonacci sequence.

Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence.

Object: Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89…

Code:

#include<iostream>
#include<conio.h>
using namespace std;
int fab(int n);
void main()
{
      int num,i=0;
      cout<<“Enter Any Number: “;
      cin>>num;
      while (i<=num)
      {
          cout<<” “<<fab(i);
          i++;
      }
      getch();
}
int fab(int n)
{
      if(n==0||n==1)
      {
          return n;
      }
      else
      {
          return((fab(n-1)+fab(n-2)));

      }
}

Output:

Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence.

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *