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

Does an owl have a backbone?
The inner and outer Radii of a cylindrical pipe are 5 cm and 4 cm respectively. find the area of cross section of the pipe.
What is the creepiest sounding scale? What scale would u use for writing creepy music in other words
Thelma spent 1/6 of her weekly allowance on dog toys.  1/4 on a dog collar and 1/3 on dog food.  What fraction of her weekly allowance is left
The inner and outer Radii of a cylindrical pipe are 5 cm and 4 cm respectively. find the area of cross section of the pipe.
What's 5 divided by x squared explain
find the sum. write each mixed number in simplest form 4 7/8 + 5 1/4
The ______ was established in 1943 to assist in the transition from a peacetime to a wartime economy ?
Does an owl have a backbone?
What is the creepiest sounding scale? What scale would u use for writing creepy music in other words