11.9k views
3 votes
H(n)=h(n)+h(n-2)

h(2)=h(1)=h(0)=1, n>=2

Write a C++ function int h(int n)

User Pavan P
by
5.3k points

1 Answer

5 votes

Answer:

#include<iostream>

using namespace std;

int h(int i)

int main()

{

int n, result;

cout<<"Enter value for n:";

cin>>n;

result = h(n);

cout<<result;

}

Step-by-step explanation:

The recurrence relation will be h(n)= h(n-1)+h(n-2), unless the recursion will not finish.

H(n)=h(n)+h(n-2) h(2)=h(1)=h(0)=1, n>=2 Write a C++ function int h(int n)-example-1
User Dave Maple
by
5.0k points