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, 21.06.2019 17:10
Type the correct answer in the box. spell all words correctly. which technology should andrea use? andrea owns a potato chips manufacturing unit. she has been getting complaints about the quality of the chips. she knows her product is good. she realizes that she needs to change the way the chips are packaged. she should use technology, which uses gases, such as carbon dioxide or argon, to create an air cushion, which improves the shelf life of products.
Answers: 2
question
Computers and Technology, 22.06.2019 21:00
Which of these is most responsible for differences between the twentieth century to the twenty-first century?
Answers: 2
question
Computers and Technology, 22.06.2019 23:00
In which part of a professional email should you try to be brief, but highly descriptive?
Answers: 1
question
Computers and Technology, 23.06.2019 04:10
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
You know the right answer?
C++ code-- factorial recursion
write code to complete printfactorial()'s recursive case. sampl...
Questions
question
Mathematics, 03.03.2021 23:40
question
Mathematics, 03.03.2021 23:40
question
Mathematics, 03.03.2021 23:40
Questions on the website: 13722363