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 16:10
When copying and pasting text, the first step is move your cursor type the text select the copy command select the paste command
Answers: 2
question
Computers and Technology, 23.06.2019 13:30
Anetwork security application that prevents access between a private and trusted network and other untrusted networks
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
What is one reason why indoor air pollution has become an increasing problem.
Answers: 1
question
Computers and Technology, 24.06.2019 23:30
Which example can be considered master data in an organization? a. holiday list b. dress code c. employee information d. recreational activities
Answers: 1
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...
Questions
question
English, 26.02.2020 08:07
question
History, 26.02.2020 08:10
question
Social Studies, 26.02.2020 08:10
Questions on the website: 13722363