C program to find factorial of a number
In this program, we will read and integer number and find the factorial using different methods - using simple method (without using user define function), using User Define Function and using Recursion.
What is factorial?
Factorial is the product of an integer with it's all below integer till 1. In mathematic representation factorial represents by ! sign.
For Example:
Factorial 5 is:
5! = 120 [That is equivalent to 5*4*3*2*1 =120]
Factorial program in C
Simple program - without using User Define Function
Output
User Define Function
Output
Using Recursion
Logic behind to implement these programs
- Variables for program - int to store number, long int to store factorial because factorial value is higher than integer value.
- Now, input the number.
- Run a loop from num to 1 and multiply the numbers in a variable called fact.
- And the fact will be the factorial after executing the loop.
need an explanation for this answer? contact us directly to get an explanation for this answer