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 statement most accurately describes a development on the U.S. home front during the cold Cold War ?
Individual city-states developed in Greece because the country was divided by Mountains Lakes Rivers
What term was used to describe the rough ride between free and slave states by the mid 1800s
What is the quotient of –10 and –5? –15 –2 2 15
Why do stomata open and close? Why is this an advantage for the leaf?
W/12 = 6/8 What is w?
Which of these BEST explains why Paul Revere is often shown riding a horse? A) He rode it during the Boston Tea Party. B) He began the Pony Express mail s
Identify two effects if the glorious revolution on the English monarchy
in his work The Spirit Of Laws, what did the french philosopher Baron De Montesquieu say about the power of government?
Yo todavía no ______ empezado a leer el libro. A. has B. hemos C. han D. he