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 is the simplified form of the expression 3(7/5 x 4) -2(2/3-5/4 x) ?
why did thomas jefferson oppose hamilton’s national bank
when are functional documents used? a. when planning an event b. when sharing research c. when looking for a job d. when writing an e-mail
read this excerpt from mark twain's life on the mississippi: he would speak of the 'labboard' side of a horse in an easy, natural way that would make one wish h
answer choice The form of "you" that you use for one person that you do not know very well is "usted."?? True False
Which form does a verb take when the subject receives the action?
when you return an item, you might be charged a ______ fee.
what should you pay attention to when you see a title for the first time?
Drought and leaching have contributed to the process of _______, a major environmental challenge in Africa A) animal endangered B) reforestation C) desertifi
when are functional documents used? a. when planning an event b. when sharing research c. when looking for a job d. when writing an e-mail