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
monitta
4 years ago
6

Create a function that will return the nth Fibonacci Number where n is an integer passed as an argument. Demonstrate the functio

n in a program.
Computers and Technology
1 answer:
jek_recluse [69]4 years ago
7 0

Answer:

Here is code in C++.

// include header

#include<bits/stdc++.h>

using namespace std;

// function to calculate the nth Fibonacci term

int nth_fib(int num)

{   // base case for the recursive function

if (num <= 1)

 return num;

 // calculate the Fibonacci term by adding last two term of the sequence

return nth_fib(num-1) + nth_fib(num-2);

}

int main ()

{

   // variable to read term

int num;

cout<<"Please Enter the number: ";

cin>>num;

// calling the function to return the nth term of Fibonacci sequence

cout <<"The "<<num<<"th Fibonacci term is: "<<nth_fib(num);

 

return 0;

}

Explanation:

Declare a variable "num" to read the term. Call the function nth_fib() with parameter "num"; .In the nth_fib(),if num is less or equal to 1 then it will return(base case of recursive function).Otherwise it will calculate the Fibonacci term by adding the previous two terms. When it reaches to base condition, The function will return the nth term of sequence.

Output:

Please Enter the number:6

The 6th Fibonacci term is: 8

You might be interested in
Drag the tiles to the correct boxes to complete the pairs.
sertanlavr [38]

Answer:

Explanation:

IaaS - storage and network devices

SaaS - software upgrades and patches

MaaS - monitoring tools

PaaS - virtual computing platform

7 0
3 years ago
A powerful computer that acts as a hub for other computers is a called a ______.
zhannawk [14.2K]
It is called a server
7 0
3 years ago
Read 2 more answers
A computer system has a 32KB, 8-way set associative cache, and the block size is 8 bytes. The machine is byte addressable, and p
vagabundo [1.1K]

Answer:

Offset bits: 3-bits

Set number of cache: 12-bits

Tag bits: 7-bits

22-bit physical address

Explanation:

Since the system is 32K so,

=2⁵.2¹⁰

=2¹⁵

As we know that it is 8-way set associative so,

=2¹⁵/2³

=2¹⁵⁻³

=2¹²

2¹² are cache blocks

22-bit physical address

Off-set bits are 3 as they are calulated from 8-way set associative information.

Set number of cache : 12-bits

For tag-bits:

Add off-set bits and cache bits and subtract from the total bits of physical address.

=22 - (12+3)

=22 - 15

=7

3 0
3 years ago
Write a program that inputs two characters first and second, and then prints all non-alphabetic characters starting from second
baherus [9]

Answer:

fbtcft gdfgfffff tvfft gxf

8 0
3 years ago
Anybody wanna join a zoom or inv me to one u can just put the link on here
aalyn [17]

Answer:

NO thanks stranger danger!

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • You would like to set up on online meeting to communicate with colleagues on a group project. Which of these tools should you su
    5·2 answers
  • Chevening is looking for individuals with strong professional relationship building skills, who will engage with the Chevening c
    15·1 answer
  • The _______________ is a priority-ordered list of the other carrier networks and frequencies it should search for when it cannot
    6·1 answer
  • Instructions:Select the correct answer.
    5·1 answer
  • Write down <br>the three part of a computer<br>​
    5·1 answer
  • 2.cite at least 2 example on how multimedia facilitates learning​
    6·1 answer
  • Why would you browse by entering a URL rather than use a link in a Web page
    15·1 answer
  • ASAP PLEASE the online research you did to describe how Senet is related to the culture and historical period when it was create
    9·1 answer
  • Hypertext enables you to navigate through pieces of information by clicking the __________, that connect them.
    8·1 answer
  • What are the two different types of dns requests?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!