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 was Hammurabi purpose for writing the code of Hammurabi
164 = 5x-7(4x-7) can you guys make the steps a little bit simpler? please and thank you <3
A divergent boundary at two oceanic plates can result in
What is 5 - 3/20 ? A. 3 17/20 B. 3 3/20 C. 4 3/20 D. 4 17/20
An onject is.launched from platform. Its height (in meters) x seconds after the launch is modeled by h(x) =-5(x+1)(×-9) How many seconds after launch will the o
is china located in the middle east?
whats has the same slope of 6x-3y=9
1. All thriving things need energy in order to __________________ and ________________ 2. Compare and contrast photosynthesis and cellular respiration. Includ
describe more than one side of a difficult situation you may have faced?
What are the relationship s are spoken in Confucian?