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

Which energy conversion must occur in an operating electrolytic cell? (1) electrical energy to chemical energy (2) electrical energy to nuclear energy (3) chemi
Where is the Statue of Liberty?
How do you multiply a decimal? For exapmple,2.4 times 3.5
What are two Cabinet-level positions?
How do you multiply a decimal? For exapmple,2.4 times 3.5
Compared to the physical and chemical properties of the compound NO2 the compound N2O has (1) different physical properties and different chemical properties (2
the sum of two integers is -1. the product of the integers is -72 find the integers.
A machine with a mechanical advantage of 10 is used to produce an output force of 250 newtons. What input force is applied to this machine
What are the two major political parties in the United States?
What do we show loyalty to when we say the Pledge of Allegiance?