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

Which term describes the example below? A child with a widow’s peak has a mother who is homozygous dominant for a widow’s peak and a father who is homozygous do
Explain why shorelines are always changing
What is significant about Gatsby keeping watch over Daisy at the end of the chapter? In the Great Gatsby
area is 320 square feet width is 4/5 length
Your uncle is planting an 8-foot tall tree. He ties support wires to the tree, 1 foot from the top, and ties them to posts on the ground, 4 feet from the trunk
How many hawksbill turtles are left in the world?
Sacha has 4 quarters in her pocket.she has 6 timés as many quarters in her piggy Bank. Draw a picture to show thenumber of quarters sacha has in her piggy Bank.
How did world war 1 contribute to the collapse of the Russian monarchy?
An animal with a coelom, jointed appendages, and metameric segmentation would be classified in the phylum (A) Mollusca (B) Cnidaria (C) Platyhelminthes (D)
what types of units are used to describe area?