Factorial of a positive number is a number which is obtained by multiplying all sequence of number starting with 1 till the number itself. Thus factorial calculation is a repititive process and recursion is often used for this.
unsigned int factorial(unsigned int n ) { if ( n <= 1 ) { return 1; } else { return n * factorial(n - 1);/*Call itself*/ } }
factorial can also be done using normal loop based logics. Below is non-recursive code sniffet.
unsigned int factorial(unsigned int n ) { int result = 1; for (i = n; i > 1; i--) { result = result * i; } return result; }
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Most popular
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average