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

Can u paraphrase the quote ”let things take their course”
is it possible for a distance versus-time graph to be a vertical line?
A pound of seedless red grapes costs $2.75. Drew must spend less than $9.35 on a bunch of seedless red grapes.Inequality:Solution:Interpretation:
in what ways is climate controlled by the sun and the water cycle ?
A 1 digit number and a 3 digit number have a sum of 205.  The same two number have a difference of 195, a product of 1,000 and a quotient of 40.  What are the t
Can u paraphrase the quote ”let things take their course”
A child is standing across the street from his apartment . His mother is on their balcony . The angle of elevation between the child's eyes and his mothers eyes
What is a direct combination reaction?
When was William Shakespeare born
in an expression(8/9) squared (-81)+3/5dividedby-9/10