subject
Computers and Technology, 19.10.2019 11:30 Deemon

C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sample output if userval is 5:
5! = 5 * 4 * 3 * 2 * 1 = 120
#include
using namespace std;

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;

}
}

int main() {
int userval = 0;

userval = 5;
cout < < userval < < "! = ";
printfactorial(userval, userval);

return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
After you clean an engine with hot water spray, it seems to stall; when it doesn't stall, it's idling noisily. technician a says to check for loose bolts on the flex plate near the torque converter. technician b says to wipe down the spark plug wires and the distributor cap. who is correct? a. technician a b. both technicians a and b c. technician b
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
What is the main benefit of minimizing the ribbon in word? more options will be accessible through customized keystrokes. more of the document will be viewable without needing to scroll. fewer controls will be accessible to the user by using the mouse. fewer editing options will be available without entering a password.
Answers: 1
question
Computers and Technology, 23.06.2019 04:31
Selling a product through an electronic medium is
Answers: 1
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...
Questions
question
Mathematics, 11.01.2021 20:50
question
English, 11.01.2021 20:50
question
Spanish, 11.01.2021 20:50
question
Mathematics, 11.01.2021 20:50
question
English, 11.01.2021 20:50
question
Mathematics, 11.01.2021 20:50
question
Mathematics, 11.01.2021 20:50
Questions on the website: 13722367