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

Find the GCF of 189 and 200 using prime factorization
A recipe that makes 6 servings calls for 1/2 cup of butter. Nancy modifies the recipe so that it can serve 8 How many cups of butter does Nancy need?
What were Elizabeth I most prominent traits as a ruler?
what is it called when the species change over time
The most diverse colonies were ______________. the southern colonies the backcountry the New England colonies the middle colonies none of these
Express the number 20000 as a single digit integer times a power of 10
What is the absolute value of 2-x=12
What were Elizabeth I most prominent traits as a ruler?
What is the sl unit for length
Which genetically engineered medicine is used to treat patients who have growth defects? insulin flu shot human growth hormone penicillin