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

Please help! I will mark as brainliest IF answer is right. <3
Help me check my answers for my homework please
Decrease 20 by 1/4 how do You do it
what are the essential functions of the nervous and skeletal system ​
A Paragraph on Fashion
What caused more than half of the Plymouth colonists to die? a shipwreck a battle with the Native Americans a deadly illness a harsh winter
Skylar and Rodrigo each recorded how far they traveled while skateboarding. Skylar traveled 65 feet in 5 seconds and Rodrigo traveled 108 feet in 8 seconds. How
whats a better ending to the story "the gift of the Magi"?​
− 16 = someone please help me with this problem
Visit these websites to see examples of how dancers are athletes and athletes are dancers: • https://www.nytimes.com/1978/11/27/archives/ballet-dancer-on-a-ball