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

Gianna skied three times farther than Xavier. Xavier skied four miles. How far did Gianna ski?
Amphibians can breathe through their skin. true or false?
what method did the Union used to stop most of the South's cotton trade
what is 9\25 in it simplest form?
The three major types of faults are normal, reverse and syncline.
What is the mass of a 735-N weight on Earth? A. 73.5 kg B. 75.0 kg C. 334.1 kg D. 725.2 kg
A toy that was originally $35 is now marked down to $28. What percentage was the toy marked down?
In a nuclear reaction, energy is released by the combination of two elements into a new element. This process is an example of
the stock market crash triggered the beginning of the great depression, the worst economic crisis in U.S. history. which factor did not contribute to the crash?
two problems that led to romes decline