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
What type of selection can be used in leu of switch/case?
tankabanditka [31]
An if or else statement can be
7 0
3 years ago
Read 2 more answers
2. The factorial of a positive integer n is the product of the integers from 1 to n. You can express the factorial of a positive
Molodets [167]

Answer:

import java.io.*;

import java.util.Scanner;//importing the scanner.

class Factorial {

public static void main (String[] args) {

    Scanner fact=new Scanner(System.in);//creating a scanner object for taking the input.

    int t,n;//t for number of times the user want to calculate the factorial and n for factorial.

    System.out.println("How many times you want to calculate the factorial");

    t=fact.nextInt();//taking input of t.

    while(t>0)

    {

        int f=1;//f for calculating the variable.

        n=fact.nextInt();//taking input of n .

        if(n>10||n<1)//if n is out of range then again taking input.

        {

           while(n>10 || n<1)

                {

                        System.out.println("Please Enter the Valid Input");

                 n=fact.nextInt();

                }

               for(int i=1;i<=n;i++)//calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

        else // if n is in  range then definitely calculating the factorial.

        {

             for(int i=1;i<=n;i++)// calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

    }

}

}

Output:-

How many times you want to calculate the factorial

2

-5

Please Enter the Valid Input

4

The factorial is: 24

5

The factorial is: 120

Explanation:

The above written code is for calculating the factorial of an integer the number of times user want to calculate the factorial.The code wants user to enter again until the value entered by the user is in range.If the value is in range then it definitely calculates the factorial.

6 0
3 years ago
Problem (Commands): Let c be a copy flag and let a computer system have the set of rights {read, write, execute, append, list, m
dlinn [17]

Answer:

Aee explaination

Explanation:

1.

command copy_all_rights(p,q,s)

if read in a[p,s]

then

enter read into a[q,s];

if write in a[p,s]

then

enter write into a[q,s];

if execute in a[p,s]

then

enter execute into a[q,s];

if append in a[p,s]

then

enter append into a[q,s];

if list in a[p,s]

then

enter list into a[q,s];

if modify in a[p,s]

then

enter modify into a[q,s];

if own in a[p,s]

then

enter own into a[q,s];

end

2.

command copy_all_rights(p,q,s)

if own in a[p,s] and copy in a[p,s]

then

enter own into a[q,s];

if modify in a[p,s] and copy in a[p,s]

then

enter modify into a[q,s];

if list in a[p,s] and copy in a[p,s]

then

enter list into a[q,s];

if append in a[p,s] and copy in a[p,s]

then

enter append into a[q,s];

if execute in a[p,s] and copy in a[p,s]

then

enter execute into a[q,s];

if write in a[p,s] and copy in a[p,s]

then

enter write into a[q,s];

if read in a[p,s] and copy in a[p,s]

then

enter read into a[q,s];

delete copy in a[q,s];

end

3.

"q" would be the effect of copying the copy flag along with the right, because q would have copy right to transfter to another, which may not be intended.

3 0
4 years ago
If you are using a sprite for your MakeCode Arcade game, which code block
xeze [42]

Answer:

set mySprite block

Explanation:

BRAINLIEST?

8 0
2 years ago
Read 2 more answers
Which of the following rules need to be followed when using variables?<br> Choose all that apply.
Masja [62]

Answer:

- All variable names must begin with a letter of the alphabet or an. underscore( _ ).

-After the first initial letter, variable names can also contain letters and numbers.

-Uppercase characters are distinct from lowercase characters.

-You cannot use a C++ keyword as a variable name.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Which is NOT a reason to study science?
    13·1 answer
  • To protect your answers after completing an assignment, what should you do? close your browser window. let someone else start wo
    14·1 answer
  • Iisa is creating a resume in which section should she mention her career goals
    6·1 answer
  • Jimmy is running out of desk space. He keeps three computers on his desk. The three computers can’t be moved, and they need to b
    5·2 answers
  • Regarding the systems development​ process, ________ addresses the​ question, "Is the system producing the desired​ results?"
    12·1 answer
  • While accessing mail through the mail command interface, a user sees 5 new messages in his mailbox. Since the second message app
    13·1 answer
  • Which of these is an example of a mobile app?
    12·2 answers
  • Someone help meeeeeeeee plz.......................
    11·2 answers
  • Question 8 of 10
    12·1 answer
  • Which new development in malware caused sandbox technology to automate and introduce artificial intelligence learning
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!