Question: For this snippet in C + + you will implement factorial both iteratively and recursively. For the iterative implementation simply take in the value to
For this snippet in C you will implement factorial both iteratively and recursively.
For the iterative implementation simply take in the value to factorialize and call it x Create a for loop counting backwards from x to meaning stop after the and before the Create a variable fact before the loop. Call the counting variable of the loop i for ix i i; the loop control. Inside the loop you execute fact fact I; this is the creation of the factorial. Print the result.
For the recursive version use:
long fact int x
long ans;
if x return ; trivial case
else
ans x factx; the reducing step
returnans;
HINT: factorials get very big, very fast, be careful of overflow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
