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

how do you solve 2.75+.003+.158=
How far away is Canopus in kilometres?
what group was successful in achieving its goals at the congress of vienna , nationalists conservatists liberals or anarchists?
Find the sum of 2/9+1/9?
What are preventable injuries and unpreventable injuries
what is 3 2/5 times 2 1/3
The fetus is nourished by the __________ during the first 7 weeks and by the _______ from week 8 through birth ?
A moving company is trying to store boxes in a storage room with a length of 5 m, width of 3 m and height of 2 m. How many boxes can fit in this space if each i
If y=2 when x=3. What is the value of y when x=9?
how do you solve 2.75+.003+.158=