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 10:30
What can tanya do now to start preparing for the college and scholarship application process? think about her grades, activities in which she can get involved, possible part-time jobs at which she can work, and standardized tests she can take. (10 points) apex
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
How should you specify box sizes on a web page if you want the boxes to vary according to the font size of the text they contain? a. in pixels b. in inches c. as percentages d. in em units
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
The more powerful, 60 volt cables and the main power shut off on an hev are both colored orange
Answers: 1
question
Computers and Technology, 23.06.2019 21:00
Alcohol’s affects on the cornea and lens of the eye make it more difficult
Answers: 1
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...
Questions
Questions on the website: 13722360