i am not getting any idea about calculating it for large numbers(thoght of using string for large number but unable to implement it totally as we can’t multiply numbers in string )
could you please give me hint (not solution).
Doubt in broken calculator
Hi!
You can do it with the help of arrays!
Create an array Residue[] of size MAX, here MAX represent the Maximum number of DIGITS that output can have. Take MAX =1500 as bigger numbers like 500 have more than 1000 digits.
Now initialize Residue[0]=1(as 0!=1) and residue_size=1.
For all numbers from x = 2 to n,Multiply x with res[ ] and update res[ ] and res_size to store the multiplication result
Now, create a function multiply(int x, int res[], int res_size)
for i = 0 to res_size – 1{
create a new variable, say product= res[i] * x + carry;
Store last digit of product(product % 10) in res[i]
and remaining digits(product/10) as carry
}
Hope this helps, All the best!