Calculating the factorial of a number is a basic excercise while learning to program in C, many of us have done it iteratively, it can also be done recursively. I am posting both iterative and recursive versions below.

Code: C

/* Recursive Version */

unsigned int recursive_factorial(int n)

{

return n>=1 ? n * recr_factorial(n-1) : 1;

}

/* Iterative Version */

unsigned int iter_factorial(int n)

{

int f = 1;

int i;

for(i = 1; i <= n; i++)

{

f *= i;

}

return f;

}