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

4Σn=! n/n! I understand what the denominator, n! is by definition. I just don't understand what to put for the numerator when n = ! Can anyone help me figu
A cross-country skier reaches the 3-km mark of a race in 15 min and the 12-km mark 45 min later. Find the speed of the skier. ​
Which is a function of x?
let vector a={1,1,1} and b={2,-1,-1} the angle between two vectors is
how do i solve this?
Which of the following does NOT describe the purpose and practice of selling stocks? Companies often raise money for operations or particular ventures by sel
Horseplay or practical jokes A. are permitted if no one is insulted B. May be done during breaks or study time C.cause accidents and have no place in the lab D
Please help me!!! I really need help on this question I promise to mark brainlest!
Rick agrees to buy 20 acres of land from tina. three weeks before the deal is to close, rick calls tina and says, "the deal is off!" in this situation, rick's a
In Figure 1, starting from the left, what magnetic poles are shown on the two bar magnets?