How can I store 500! in a variable?
long long int wont work for that.
Broken Calculator
hello @anshgoel_02
yeah u cant store such big numbers in long long or any other primitive datatype.
the idea is to use array.
intially the array will hold 1. (indicating 1 factorial)
and then iterate from 2 to n(to compute n!) , multiply this number with the number available in array and update the array.
for example if u have to store 23 in array then store it as
3 | 2
now let say u have to multily this number 23 with 2 .
so simply iterate this array and multiply by 2 but do take care of carry
6 | 4
for printing simply iterate from right to left.
refer this code for clarity->