• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
204 views

Problem:

Write code to complete printfactorial()'s recursive case. sample output if userval is 5:

Sample output if userVal is 5:

5! = 5 * 4 * 3 * 2 * 1 = 120
by (550 points)  
edited by

1 Answer

0 votes

Solution:

#include 

void PrintFactorial(int Counter, int Value){
   int nextCounter = 0;
   int nextValue = 0;

   if (Counter == 0) {            
      printf("1n");
   }
   else if (Counter == 1) {       
      printf("%d = %dn", Counter, Value);
   }
   else {                             
      printf("%d * ", Counter);
      nextCounter = Counter - 1;
      nextValue = nextCounter * Value;

      

   }
}

int main(void) {
   int inputVal = 0;

   userVal = 5;
   printf("%d! = ", inputVal ) 
   PrintFactorial(userVal, inputVal );

   return 0;
}

by (290 points)  
...