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

(X+12) 2 ÷ x2-144 ×-12. 12×-144
What is the coefficient of y in the expression 12+3y-2x?
what is the meaning or definition of fighting-gear??
what is the cause and effect for the french citizens armies win their revolution for liberty and equality
The Indus, Ganges, and Brahmaputra were important to ancient India because they were
other name for blood
Find an equivalent ratio for 22/55 then write the proportion ?
Which of the following rivers is the world's busiest waterway ?
The graph of y = 4x - 11 is translated up 8 units. Which equation represents the translated graph? f y = 4x - 19 g y = 4x - 3 h y = 12x - 11 j y = 12x - 3
The entire region of Northern Africa and southwest Asia has a climate generally described as?