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

explain the function of ribosomes and why cells need them
Identify the sentence with all words spelled correctly. a. Silvio and​ Lena's marrage ceremony took place on the beach. b. Javier had to renew his​ driver's lic
Whys is it helpful to write a number as a product of primes
Hammurabi's Code brought a sense of fairness to his people and established order in society. a. True b. False
If someone is a “nativist,” who is he or she against?
Tickets to a museum cost $17 each. For a field trip, the museum offers a $4 discount on each ticket. How much will tickets for 32 students cost?
In the village of Moon there are three weavers, two bakers, and a jeweler. The village has a granary as well as an open air market where most residents buy thei
how many times can 21 go into 336
Show the work for 2 divided by 50
Free-market economies use ______ to distribute goods, services, and resources A.Price B. Command C.Government