1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
polet [3.4K]
3 years ago
5

C++ Fibonacci

Computers and Technology
1 answer:
liq [111]3 years ago
4 0

Answer:

int ComputeFibonacci(int N) {

   if(N == 0)

       return 0;

   else if (N == 1)

       return 1;

   else

       return ComputeFibonacci(N-1) + ComputeFibonacci(N-2);

}

Explanation:

Inside the function ComputeFibonacci that takes one parameter, N, check the base cases first. If N is eqaul to 0, return 0. If N is eqaul to 1, return 1. Otherwise, call the ComputeFibonacci function with parameter N-1 and N-2 and sum these and return the result.

For example,

If N = 4 as in the main part:

ComputeFibonacci(4) → ComputeFibonacci(3) + ComputeFibonacci(2) = 2 + 1 = 3

ComputeFibonacci(3) → ComputeFibonacci(2) + ComputeFibonacci(1) = 1 + 1 = 2

ComputeFibonacci(2) → ComputeFibonacci(1) + ComputeFibonacci(0) = 1 + 0  = 1

*Note that you need to insert values from the bottom. Insert the values for ComputeFibonacci(1) and  ComputeFibonacci(0) to find ComputeFibonacci(2) and repeat the process.

You might be interested in
There is an enormous amount of information on the Internet that is automatically separated into good content and not-so-good con
Lena [83]
False u would figure out yourself if it's good or bad
6 0
3 years ago
Answers for this question​
horsena [70]

Answer:

What is the question?

Explanation:

4 0
3 years ago
Not all output display data for humans to read explain why​
Vadim26 [7]

Answer:

The eye has a very focused view that is optimised for perceiving movement.Human cannot see clearly outside an -5 degree cone of foveal vision.

8 0
3 years ago
What is the new file system available in windows server 2012?
exis [7]
Windows 2012 introduced a proprietary File system to success NTFS with ReSF (Resilient File System). There are many improvements made over NTFS as larger disks sizes, better quota management, additional attributes etc. also, the speed has significantly increased. There are many more improvement that you can simply Google.
6 0
4 years ago
What type of micro sd card is needed for this type of MP3 player? I tried searching it up and a bunch came up. I don’t know whic
zaharov [31]
A regular micro sd, they offer different amounts of storage
8 0
3 years ago
Other questions:
  • What is cryptocurrency ? I need to do a research one it please help!
    6·1 answer
  • Which component of the Hyper-V architecture controls all communication with the physical hardware on the computer?
    8·1 answer
  • What is the purpose for adding images and graphics to a web page?
    5·1 answer
  • An additional factor in how an element is rendered is that properties are passed from a parent element to its children in a proc
    15·1 answer
  • Which four of the following hardware components are specifically used to enable networking and are not part of a stand-alone com
    13·2 answers
  • Your mother wants to purchase a large hard drive for her computer and asks you to see what type of drive interface she has. Her
    13·1 answer
  • 1. Why is it important for IT technicians to keep documentation on computers for which they are
    13·1 answer
  • Describe how to create a new folder on the desktop​
    12·2 answers
  • Jason is using his mother's computer. He plugs in his flash drive, but it does not appear in the explorer window. Suggest what J
    12·1 answer
  • 8. Software ____ are individual programs that can be purchased, installed, and run separately, but extract data from the common
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!