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 someone help me out with this question fast!?!?!
What is a tree? I’m graduated so my points are up for grabs cause I’ll never use them. I have to at least as a question with it though.
Where is the moon? I’m graduated so my points are up for grabs cause I’ll never use them. I have to at least as a question with it though.
f+1<5 please tyyyyyyyyyyyyyyyy
A watermelon weighs 4.2 kg and a pumpkin weighs 2 kg 250g Express the total weight of the items in kilograms. (30 points​
26. Which of the following is an equation for the line that is perpendicular to the line y = 2x - 9 and passes through the point (-4,5)? A. y = 2x+7 B. y = -1/
What measurement could be the length of a pool?
Why does my screen keep showing R/34 pictures of boots the monkey? I’m graduated so my points are up for grabs cause I’ll never use them. I have to at least as
What is the formula of Sodium Sulfide? A) Na3S₂ B) NaS₂ C) Na₂S D) Nas
Governments collect taxes to