The program to compute factorial calls a function recursively to compute the output.The recursion is the ability of a computing procedure to call itself repeatedly until the problem is solved.
We compiled the program using Dev C++ version 5 (beta) compiler installed on Windows 7 64-bit system. You can use any standard C compiler, but make sure to change the source code according to compiler specifications.
You must know the following c programming concepts before trying the example program.
- C Arithmetic Operators
- C Reading Input Values
- C Variables and Constants
- C Flow Control Structures
- C Functions
In simple words, the factorial of a given number n is the product of all the numbers up to that number, including the number.
So factorial of 5 is 1 x 2 x 3 x 4 x 5 = 120
In the previous section, we introduced you to the concept of recursion.To elaborate on that see the example below. If
factorial () is a function then,
Every time factorial function calls itself, it reduces 1 from the parameter of the function until the
factorial (1) is reached. Then it starts processing or working from
factorial (1) to the top –
factorial (n) and prints the final results.