aubreejordan6952 aubreejordan6952
  • 04-07-2019
  • Computers and Technology
contestada

h(n)=h(n)+h(n-2)

h(2)=h(1)=h(0)=1, n>=2

Write a C++ function int h(int n)

Respuesta :

SerenaBochenek SerenaBochenek
  • 14-07-2019

Answer:

#include<iostream>

using namespace std;

int h(int i)

{

if(i==0 ||i==1||i==2)

 return 1;

else

 return(h(i-1)+h(i-2));

}

int main()

{

int n, result;

cout<<"Enter value for n:";

cin>>n;

result = h(n);

cout<<result;

}

Explanation:

The recurrence relation will be h(n)= h(n-1)+h(n-2), unless the recursion will not finish.

Ver imagen SerenaBochenek
Answer Link

Otras preguntas

PLEASE HELP I GIVE THANKS
If x= 0, 1, 2, and 3 and y=1, 1.5, 2, and 2.5, then what is the "y=" function?
What was an effect of major environmental issues that occurred in the 1960’s?.
Which statement about the U.S. Constitution is true? A. It called for judges to be appointed for a limited term of office. B. It is an expanded version of Thoma
Let “x” be the number of apples in a barrel. Which of the following is the expression that represents one less than twice the number of apples in the barrel?
How do I apply the change of base formula to y=log (sub 3) x
Anna's garden has an area of 48 square feet. She plants peas in 3/8 of the garden and herbs in 1/4 of it. The rest of her garden is planted with peppers . How m
write 7340 in standard for
examples of three different types of computer storage
Real world Examples of inertia