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

Other questions on the subject: Computers and Technology

image
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
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
Computers and Technology, 23.06.2019 11:30, kieante01
The most accurate readings that you can take on an analog vom are when the meter's pointer is at the a. center scale. b. extreme right. c. near right. d. extreme left.
Answers: 1
image
Computers and Technology, 24.06.2019 10:00, RG1971
(, urgent need): how do i change my username
Answers: 1
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...

Questions in other subjects:

Konu
Spanish, 15.07.2021 22:20