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

1. Which of the following is the correct order from DNA to traits a. Proteins --> DNA --> genes --> traits b. DNA --> genes -> protein --> tai
Which of these was important to Olmec agriculture? A. slash-and-burn techniques B. crop rotation C. cattle domestication D. plantation farming
What is the difference between shifting cultivation and land rotation?​
use parler to for a french sentenceuse parlour to form a French sentence ​
Fill in the blanks in the following sentences with the appropriate word(s). 6. Est-ce que tu as l'______de Marie? Je veux lui envoyer une carte postale. 7. Je s
If Birr 2400 is invested at 6 simple interest per annum, then what is the amount after 4 years?
Who could help me with this question (have only 1 try)
explain the Communist Party’s purpose for writing and popularizing the song “The East is Red.”
Which of the following was NOT an agency created under Nixon's Presidency A) EPA B) CIA C) OSHA D) DEA
helppppppppppppppppp