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

The graph of y = 4x - 11 is translated up 8 units. Which equation represents the translated graph? f y = 4x - 19 g y = 4x - 3 h y = 12x - 11 j y = 12x - 3
(X+12) 2 ÷ x2-144 ×-12. 12×-144
The process by which rocks are broken down into smaller fragments by the atmosphere and other factors in the environment is called?
The diameter of your bicycle wheel is 25 inches. How far will you move in one turn of your wheel?
The neolithic revolution is most closely associated with....
what is the cause and effect for the french citizens armies win their revolution for liberty and equality
16 increased by twice a number is -24. Find the solution??
The base of right prism is rhombus of diagonal is 6 and 8cm and altitude is 12 cm find total surface area
what is the cause and effect for the french citizens armies win their revolution for liberty and equality
other name for blood