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;
}


but one small comment
:
The " unsigned int " type can memorize a value between 0 and +4,294,967,295 but " 1000! " is more much greater than the dimension of " long double " which is the greatest data type in C/C++. I think this is a good question.
