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

A number ending in ___ is never a perfect square. ​
4 Describir la revolución Haitiana. 1804​
1/3=?/24 Which number is missing to make the equation true?​
Please help me out with these questions :
if 5 breads for $100 and they want 2000 breads how much will it cost​
Compare 3/10 and 1/5 by creating common denominators. then draw fractions models to show that you have written the correct sign. PELASEEEEEE
determine lcm and HCF of 24 and 26 using prime factors​
a/b=2/5 and b/c=3/8 find a/c​
The square root of the variance is called the: standard deviation beta covariance coefficient of variation
Groups of countries that seek mutual economic benefit from reducing interregional trade and tariff barriers are called