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

What were FDR'S for the end of war?
Find the volume of the rectangular prism. A) 19 in3 B) 57 in3 C) 144 in3 D) 288 in3
The equation of a circle is x2+y2+10x−4y−20=0 . What is the radius of the circle?
Answering these 3 questions
Whats 4 1/2 * 6/100 explain please! Thank you!
the tests done to determine if someone is HIV positive are called enzyme
Why is it important to cite sources correctly in a paper?
Which of the following nations used social media sites to organize protests?
How does a sound wave increase the kinetic energy of the particles in a medium
A day care program has an average daily expense of $75.00 the standard deviation is $15.00. The owner takes a sample of 64 bills. What is the probability the me