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

What natural polymer makes up paper
Find the x and y intercepts of the function
Refer to Explorations in Literature for a complete version of this poem.In "Daystar" by Rita Dove, how does the image of the woman closing her eyes and wanting
There are 4 juice cartons and 7 milk cartons in the school refrigerator. What is the ratio of juice cartons to total cartons? (A) 3 to 4 (B)3 to 11 (C)4 to 7
In at least 150 words, evaluate the manner by which congressional districts are formed in the U.S. Do you think this is a good system for electing representativ
maple street is 3 times as long as pine street . how long is pine street? maple street length 21
What is the solution of |x-5|-2=10?
The function f(x)=x^5 + (x+3)^2
Which can you use to lead a paragraph when you want to hook your readers?
The type of relationship described could best be classified as one of