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
Serjik [45]
3 years ago
10

C++ code-- Factorial Recursion

Computers and Technology
2 answers:
Aloiza [94]3 years ago
3 0
Handle the print outside of the factorial function, which only needs one userVal when called.

int factorial( int foo )
{
  if( foo == 1 )
   return 1;
 else
   return( foo * factorial( foo - 1 ) );
}
oksano4ka [1.4K]3 years ago
3 0

Answer:

void PrintFactorial(int factCounter, int factValue){

int nextCounter = 0;

int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1

cout << "1" << endl;

}

else if (factCounter == 1) { // Base case: Print 1 and result

cout << factCounter << " = " << factValue << endl;

}

else { // Recursive case

cout << factCounter << " * ";

nextCounter = factCounter - 1;

nextValue = nextCounter * factValue;

printFactorial(nextCounter, nextValue);

}

}

Explanation:

The only things that is left is calling the recursive function in the else statement. It is the bolded command on the answer.

factCounter is the value we are multiplying. In the function, it is nextCounter. So for 5, it is 5, then 4, then 3, until 0...

factValue is the value of the factorial. In the function, it is nextValue So it is 5, then 5*4 = 20, then 5*4*3 = 60, then...

void PrintFactorial(int factCounter, int factValue){

int nextCounter = 0;

int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1

cout << "1" << endl;

}

else if (factCounter == 1) { // Base case: Print 1 and result

cout << factCounter << " = " << factValue << endl;

}

else { // Recursive case

cout << factCounter << " * ";

nextCounter = factCounter - 1;

nextValue = nextCounter * factValue;

printFactorial(nextCounter, nextValue);

}

}

You might be interested in
How to cheat on asseeprep
Burka [1]
Just do it just look up the answers mate
6 0
2 years ago
Hidden costs of computers into our schools
Gala2k [10]

Answer:

There are certainly many hidden costs, and you need to find them out. I am listing some. The GPU can cost a lot if you are using them for complex computing like in the case of Bitcoin. You need to pay heavy electricity bills as well. And if you want to install the webserver then as well, you need to keep your computer open all the time, and pay a good sum as an electricity bill. Many more hidden costs can be found. And one out of above is used in Schools, the webserver. Some more hidden costs can be Network cost, as the school is big, and you need to connect all through LAN, and at times we also need WAN set up. And these are another hidden cost. Various education licenses come for free, and smart classes cost as well. The video conferencing, VOIP, etc costs as well. Smart classes training by various computer training institute for teachers like one from adhesive.

Explanation:

Please check the answer section.

6 0
3 years ago
How much is a stock supra 1998​
saveliy_v [14]

Answer:

Hatchback Original MSRP / Price Engine

Supra 3dr LB Auto $31,078 / $29,122 6 Cylinder

Supra 3dr LB Sport Roof Auto $35,648 / $32,842 6 Cylinder

Supra 3dr LB Sport Roof Turbo Auto $38,778 / $35,903 6 Cylinder Turbo

Supra 3dr LB Sport Roof Turbo Manual $40,508 / $37,362 6 Cylinder Turbo

Explanation:

5 0
3 years ago
Which of the following is not an example malicious code<br> A.Trojan horse B.worm C.virus D.spygear
umka21 [38]
B would be the correct answer

7 0
3 years ago
Read 2 more answers
What is a spreadsheet​
Delicious77 [7]
A spreadsheet function that indicates the average of a group of numbers in a range.
8 0
2 years ago
Other questions:
  • What is a browser? Give one example
    8·2 answers
  • What is the definition of a server?
    11·1 answer
  • True or false. Embedding only part of a font is called presetting.
    14·1 answer
  • Match each type of software license with the appropriate definition.
    11·1 answer
  • A collection of realated files is called a
    12·1 answer
  • List at least 5 professions for people working in the Information/Communication<br> fields.
    10·1 answer
  • Lab 6B: printing a binary number
    13·1 answer
  • Your first submission for the CIS 210 Course Project should include the following functionality: - Requests the user to input hi
    13·1 answer
  • What is the benefit of making an archive folder visible in the Outlook folder list?
    6·1 answer
  • How should you schedule a meeting with someone in another time zone?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!