Write a Program in C to calculate an print the factorial of a number.

Factorial of any number is

## Factorial using While Loop

So to calculate factorial of a number using while loop we need to run while loop until n!=0, each time decreasing the value of n by 1 and multiplying the number to the resultant value.

Output ## Factorial using For Loop

To calculate factorial of a number using for loop, we need to run a loop from n to 1 and multiply each number into the factorial product.

Output ## Factorial using Recursion

In recursion, we first need to find the base condition. In this problem the base condition is n=1. The computing part is to multiply the number with the recursive call with value n-1 i.e n * factorial(n-1).

Output ## Factorial using Function in C

To find the factorial of a number using a function, we need to create and call the function with the value of n. And the function should return the value of n’s factorial. So inside the function, we can use any method to calculate factorial of a number. It can be using:

• For loop.
• While loop.
• Recursion.

We will use for loop for simplicity.

Output That’s all we need to write in C, in order to calculate factorial of a number. If the program doesn’t work for you or you have any doubt then do comment below.

### This Post Has One Comment

1. Thanks a lot!