![subject](/tpl/images/cats/informatica.png)
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](/tpl/images/cats/User.png)
Answers: 2
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Other questions on the subject: Computers and Technology
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 08:10, autumnguidry1622
Technician a says that if a valve is open when a piston rises to the very top of a cylinder, the piston may actually strike the valve head and cause serious engine damage. technician b says if the camshaft is located in the engine block, then the engine is called an overhead valve engine, ohv engine, or an in-block camshaft. who is right? a. b only b. both a and b c. a only d. neither a nor b
Answers: 3
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 02:30, jalaholmes2027
Three out of five seniors remain undecided about a college major at the end of their senior year.
Answers: 3
![image](/tpl/images/cats/informatica.png)
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...
write code to complete printfactorial()'s recursive case. sampl...
Questions in other subjects:
![Konu](/tpl/images/cats/es.png)
Spanish, 15.07.2021 22:20
![Konu](/tpl/images/cats/fizika.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/istoriya.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/biologiya.png)
![Konu](/tpl/images/cats/fizika.png)