Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called My_fibonacci which calculates Fibonacci series for a non

ID: 2988906 • Letter: W

Question

Write a function called My_fibonacci which calculates Fibonacci series for a non-negative integer. Fibonacci series are deifned as follows.

Fibonacci(k) = Fibonacci(k-1) +Fibonacci(k-2);

with initial values: Fibonacci (k) = 1 for k=0,1.

The function should have k as an input (non-negative integer), an error message should be generated if the input does not satisfy the required conditions. The output of the function should be Fibonacci(k), named y. you can use the property that a function can be called within itself.

Explanation / Answer

/* Fibonacci Series */
#include<iostream.h>
#include<conio.h>

int main()
{
   int n, first = 0, second = 1, next, c;

   cout<<"Enter the number of terms ";
   cin>>n;
   if(n<0)
   {
   cout<<"does not satisfy the required conditions ";
   }
else
{
   cout<<"First "<<n<<" terms of Fibonacci series are :- ";

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      cout<<next<<endl;
   }
getch();
   return 0;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote