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 5 things cause erosion?
The reaction of aluminum with bromine is shown here. The equation for the reaction is 2 Al(s) + 3 Br2(ℓ) n Al2Br6(s) 1. What are the stoichiometric coefficients
ANOTHER 99 POINTS UP FOR GRABS What is the frequency of a wave that has a wave speed of 150 m/s and a wavelength of 0.30 m?
Use zero- through third-order taylor series expansions to predict f(3) for f (x) = 25x3 − 6x2 + 7x − 88 using a base point at x = 1. compute the true percent re
Can someone please help me with this question
Find the median of the set of data 34 36 30 37 40 30 42 ba37 b35 c36 d30
HELP IDK HOW TO FIND THE SLOPE CAN YOU PLEASE MAKE AN EQUATION LIKE Y= something x + something IDEKKK
What percent of 84$ is 21$
This map shows the spread of Buddhism. Based on the information in this map, which of the following statements is true? Buddhism started in India and spread no
Show that: (3x+7)^2-84x=(3x -7)^2