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.