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

At a dock, a crane lifts a 2009 kg container 20 m, swings it out over the deck of a freighter, and lowers the container into the hold of the freighter, which is
Two planes simultaneously left the Washington and LA and headed towards each other. The distance between the cities is 2700 miles. After they flied for 2 hours,
Mr. Bray prepares a list of 43 US presidents, 8 of whom died in office. Then 18 of his students each select a president at random (there can be repeats) for the
find a formula for p????, the payment in year ???? on a loan of 105000 dollars. Interest is 5 percent per year, compounded annually, and payments are made at th
I need help with this please
What is -18(x)=17+x/6 Evaluated
The volume of a particular die is 10600 mm3. Use the fact that 10 mm equals 1 cm to convert this volume to cm3. Round your answer to the nearest tenth​
why did jamestown ultimately survive as a permanent settlement
What is one add forty four
Given triangle ABC, which equation could be used to find the measure of <B?​