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

why was so revolutionary about the Industrial Revoluton?
What was the largest number of mushers to finish a Iditarod race?
why was so revolutionary about the Industrial Revoluton?
what is a system of millions or billions of stars, together with gas and dust held together, by gravitational attraction?
why can you compare two fractions with the same denominator by only comparing the numerators
Which "spheres" are interacting when water evaporates from plants
What battle halted the German invasion of Russia?
A number n increased by 6 is less then or equal to 4
Which of the following aspects of Wilson's Fourteen Points was adjusted, or compromised, at the 1919 peace conference? A.multi-national disarmament B.self-deter
What was the result of the Bay of Pigs invasion in 1961? A. Fidel Castro stepped down as leader of Cuba. B. Cuban forces gained ground in Puerto Rico. C. The Cu