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

can you guys plz answer this question in order and quickly plz I will give 30 points
What if flash wasnt fast but slow what would you call that
which type of reaction always has an element and a compound as reactants
what was the basic premise of the civil rights act if 1964
Need help finding this answer
ocean currents that move away from the equator carry warm, moist air and ocean currents that move away from the poles carry cooler, dryer air. Based upon this i
Jackson is a very smart little boy he can count to twenty and is only two years old. Complete, run on sentence or comma splice
NEED NOW!!!! WILL GIVE BRAINLIEST Which of the following was the most significant aspect of Revel's election to the Senate?
Find the difference 345.4 - 43.8
Gregory draws a scale drawing of his room. The scale that he uses is 1 cm : 4 ft. On his drawing, the room is 3 centimeters long. Which equation can be used to