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

uurgent please help me
PLSSS HELP IF YOU TURLY KNOW THISS
whats a cooler number 86 or 42?
Name a set of vertical angles in the image below:
In a stack of 100 newspapers, the comic section is missing from 60 papers. Lexie buys two papers from the stack. What is the probability that both papers will h
Luke and Quinten are discussing what shapes the composite figure can be broken into. Luke wants to break it into four right triangles and one rectangle. Quinten
One piece of evidence that de gante used in the excerpt to support his overall argument about the treatment of the people of mexico is that native americans.
The specific heat of a substance is the amount of energy needed to raise the temperature of:.
divide. give the quotient and remainder 295/4
Part A Match the events from the late 1980s and early 1990s with the related action by the United States. Tiles Dissolution of the Soviet Union Invasion of Pana