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

This is a c program practice. must solve this problem recursively may only make

ID: 3847510 • Letter: T

Question

This is a c program practice.

must solve this problem recursively

may only make ONE recursive call in the recursive case

For this practice you will be writing a program to calculate the value of the function foo. The value of foo is defined as follows

foo(0)=2
foo(1)=3
foo(2)=5
foo(n)= foo(n1)+ foo(n2)+ foo(n3)

Specifications

The value of n is accepted through the command line

You may only make 1 recursive call in the recursive case

1. If you don't you will fail many of the tests with a timeout issue 3. You must solve the problem recursively

Example

./foo.out 2 foo(2) = 5

./foo.out 10 foo(10) = 697

Explanation / Answer

//Use the below code to calculate the foo value.

//If you are satisfied with the answer please comment and like.

#include <stdio.h>

int foo(int n) {

  

   if(n == 0) {

      return 2;

   }

   else if(n == 1) {

      return 3;

   }

   else if(n == 2) {

      return 5;

   }

   else return foo(n-1)+foo(n-2)+foo(n-3);

}

int main() {

    int n;

    printf("Please enter foo value ");

    scanf("%d",&n);

   printf(" foo(%d)=%d",n, foo(n));

   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