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

Who is Liu Bang's wife?
Infer the direction of the net force acting on a car as it slows down and turns right.
What is a fact sheet?
Oogamy always involves fertilization from gametes of different sizes. a. True b. False
The connotations of a word have little effect on its literal meaning. a. true b. false
why do whole numbers get raised to an exponent get greater, while fractions raised to an exponent get smaller
What are the three major life processes that have to occur in animal cells?
The sum of two numbers is 60 and the difference is 2 what are the numbers.
a group of 25 sixth graders,40% of them said they had never visited another state.how many students said they had never visited another state?
what is a protective layer around all cells that controls the movement of materials into and out of the cell