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

what type of verb is the underlined word in the sentence? the amazon river winds through the rain forest of brazil. a. intransitive b. transitive
the number 0.1111... repeats forever; therefore, it is irrational.
9 m/s to a total stop. what is the objects acceleration
the term angle of deviation is used in reference to a/an
a 26-mile section of a highway is designated as a scenic byway. New signs will be placed at the beginning and end of this section and at every 0.5 mile in betwe
5)a strip of paper has a length of 14cm what is the lengh of the strip of paper in mm, and in km
what is the answer please.
Is 4 primer or composite
what is 34.5 divided by 4
Capital resources are goods made by people and: A)scarce B)are divided among members of society. C)used to produce other goods and services.