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

Describe the long term effects of competition on populations of two different species competing for the same source.
Tom gathered some mushrooms. Of those he dried 2/5 , then pickled 5/9 of the remaining mushrooms, and then fried the 28 mushrooms that were left. How many m
Which words in the sentence are the predicate adjectives? A snake's skin feels dry and smooth to the touch. Choose all answers that are correct. a. touch b. ski
How do you graph y= -x+5
what is it called when the species change over time
Esteban counted the number of steps it took him to walk to school.He counted 1,138 steps.How many steps does he take walking to and from school each day?
624 feet to 702 feet
what is the color code of desert
21/24÷7/8 show work please
how solve the equation a(n-3)+8=bn solve for n