Write a C program to calculate the value of the function koo

Write a C program to calculate the value of the function koo. The value of koo is defined as follows:

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

The value of n is accepted through the command line

You may only make 1 recursive call in the recursive case

You must solve the problem recursively

No global variables are allowed

Examples:

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

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

Solution

Answer:

#include<stdio>

using namespace std;

int foo(int n)
{
if((n==1)||(n==0))
{
return(n);
}
else
{
return(foo(n-1)+foo(n-2));
}
}

int main()
{
int n,i=0;
printf(\"Enter the value of n:\");
scanf(\"%d\",&n);
printf(\"\ foo =\ \");

while(i<n)
{
   printf(\" \");
printf(\"%d\",foo(i));
i++;
}

return 0;
}

Write a C program to calculate the value of the function koo. The value of koo is defined as follows: koo(0)=2 koo(1)=3 koo(2)=5 koo(n)= koo(n1)+ koo(n2)+ koo(n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site