Kraken Kraken - 1 year ago 72
C Question

How to find a factorial?

How can I write a program to find the factorial of any natural number?

Answer Source

This will work for the factorial (although a very small subset) of positive integers:

unsigned long factorial(unsigned long f)
    if ( f == 0 ) 
        return 1;
    return(f * factorial(f - 1));

printf("%i", factorial(5));

Due to the nature of your problem (and level that you have admitted), this solution is based more in the concept of solving this rather than a function that will be used in the next "Permutation Engine".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download