The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
This code is based on creating a recursive funciton. You cannot alter the code besides adding your solution in the particular area.
Write code to complete PrintFactorial()'s recursive case. Sample output if userVal is 5:
5! = 5 * 4 * 3 * 2 * 1 = 120
#include
void PrintFactorial(int factCounter, int factValue){
  int nextCounter = 0;
  int nextValue = 0;
  if (factCounter == 0) {           // Base case: 0! = 1
     printf("1\n");
  }
  else if (factCounter == 1) {      // Base case: print 1 and result
     printf("%d = %d\n", factCounter, factValue);
  }
  else {                            // Recursive case
     printf("%d * ", factCounter);
     nextCounter = factCounter - 1;
     nextValue = nextCounter * factValue;
     /* YOUR SOLUTION GOES HERE*/
  }
}
int main(void) {
  int userVal = 0;
  userVal = 5;
  printf("%d! = ", userVal);
  PrintFactorial(userVal, userVal);
  return 0;
}
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll