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

Help me please…………………
A vector is any quantity that has no units of measurement
Prove whether the following are identities 2tanh 1/2x / 1−tanh^2 1/2 x = sinh x​
Please answer number 26
CAN U PLS HELP ME . ASAP. PLSPLSSSSSSSSS. thank you. ​
Question 4 1 pts The five health components of fitness are flexibility, muscular strength, muscular endurance, body composition, and running O cardiorespiratory
Rewrite 1 in a have 5 barrel to 1 in a hour
please help and ty all for yall's help :) LOVE YALL!!!!!!! <3 BTW it's 20 points
Jarek is short of his sales goal this month. He knows if he adds small items to his customer's orders, they most likely won't notice the small increase and then
please help me I will mark you as Brainlist ☺️​