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

Consider the function f(n) = 5f(n - 1) - 6f(n - 2), n greaterthanorequalto 2, f(

ID: 3814719 • Letter: C

Question

Consider the function f(n) = 5f(n - 1) - 6f(n - 2), n greaterthanorequalto 2, f(0) = 0, f(1) = 1. Write a program that calculates f(n) recursively. At the start of the program, prompt the user to input an integer number by printing " Input an integer: ". If the input is negative, then print "Input must be nonnegative. ". If the input is nonnegative, then print the value of f(n) as "f() = ", where and are replaced with the values of n and f (n), respectively. You should use the following function prototype: int recursiveFunc(int n); Example input/output pairs (without the prompt) are provided below. Input: 0; Output: f(0) = 0 Input: 1; Output: f(1) =1 Input: 3; Output: f(3) = 19

Explanation / Answer

#include <iostream>
using namespace std;

int recursiveFunc(int n)
{
if(n==0 || n==1)
return n;
else
{
return (5*(recursiveFunc(n-1)) - 6*(recursiveFunc(n-2)));
}
}

int main() {
  
   int n;
   cout<<"Input an integer: ";
   cin >> n;
   if(n < 0)
   cout<<"Input must be nonnegative. ";
   else
   {
   cout<<"f("<<n<<") = "<<recursiveFunc(n)<<" ";
   }
  
   return 0;
}