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

Which word in the sentence is the direct object? My family grows vegetables in our small backyard garden. a. vegetables b. backyard c. family d. garden
1. a. Write or type the sentence that is the topic sentence of the paragraph. b. Write or type the sentence that is unrelated to the topic and can be eliminated
Which of the following is not a device used in LAN Options Mouse Repeater Hub Switch
A major obstacle to developing good human relations skills is that a. few persons have common interests. b. people fear taking risks. c. common interests won
44.88 divided by 1.2
What is 3(n + 7)=_____+21
what should a person eat if she wants the fastest supply of energy?
give me a division problem involving the division of a decimal by a whole number with an estimated quotient of 7
why photosynethis and respiration are alike in they both
what are 5 of the most common medical records documents