Problems in writing code of factorial

When the value of n changes increases by 1, the value of the factorial increases by n. So the variable storing the value of factorial should have a large size. Following is the value of n whose factorial can be stored in the respective size.

1. integer –> n<=12

2. long long int –> n<=19

From the above data, we can see that a very small value of n can be calculated because of the faster growth of the factorial function. We can however find the mod value of factorial of larger values by taking mod at each step.

The above solution cause overflow for large numbers. Please refer factorial of large number for a solution that works for large numbers.
Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.



Program for factorial of a number

Similar Reads

What is the factorial of a number?

Factorial of a non-negative integer is the multiplication of all positive integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720.  A factorial is represented by a number and a  ” ! ”  mark at the end. It is widely used in permutations and combinations to calculate the total possible outcomes. A French mathematician Christian Kramp firstly used the exclamation....

Iterative Solution to find factorial of a number:

...

Problems in writing code of factorial

...

Contact Us