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

You are to program a solution to the following problem in proper C+ +. You may (

ID: 3841247 • Letter: Y

Question

You are to program a solution to the following problem in proper C+ +. You may (1) decide that a hand-written solution works best. Or you may write a solution using the C+ + editor/compiler you have been using during the regular semester. Should you take option 2, send a copy of your program to mcwilliams@umes.edu no later than 3.30 pm today. If you choose option 1, turn your program in before you leave the room. In either case, you may not use your book or your notes. The directions of the previous part of the final exam holds. Write a function that takes a positive integer, N, as input and outputs the Nth Fibonacci number. Write a driver program to exercise the function that allows the user to repeatedly input values until the user decides to quit. Recall that the first few Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ellipsis

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;

int fib(int N)
{
if (N <= 1)
return N;
return fib(N-1) + fib(N-2);
}

int main() {
   while(true)
   {
       int N;
       cout<<"Enter N (-1 to quit): ";
       cin>>N;
       if(N==-1)
           exit(0);
       else
       cout<<endl<<N<<"th fibonacci number is "<<fib(N)<<endl;
   }
   return 0;
}

OUTPUT:

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