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

What were three things Japanese "borrowed" from Korea and China?
_____ are a group of organic compounds including fats, phospholipids, and steroids. Proteins Carbohydrates Lipids Nucleic acids
identify the stage of mitosis in which a cell spends the most time
What is a try square used for
what is 46% as a fraction in simplest form
He 25 members of the Reading Club are buying a book to discuss at the next meeting. The club leader got a special price; the book will cost $8.14 for each perso
Which geographic feature contributed to the beginning of Farming communities?
in what ways did the division of labor contribute to the growth of Mesopotamia civilization
31/9 as a mixed number
(2.5 • 10^4) - (1.5 • 10^3) Evaluate please, can you show the steps