My solution: https://ide.codingblocks.com/s/404727
Question: https://online.codingblocks.com/app/player/178555/content/173727/4748/code-challenge
Only test case 0 passed, other 6 failed - wrong answer.
My solution: https://ide.codingblocks.com/s/404727
Question: https://online.codingblocks.com/app/player/178555/content/173727/4748/code-challenge
Only test case 0 passed, other 6 failed - wrong answer.
Hey @mohaktrivedi you must be passing a single test case and failing rest. Reason for that is you will be having value of N in range of 1 to 500,
factorial of 100 is
100 ! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
No data type can store this much value as the logic you are using, won’t be applicable in solving this problem. So you have to think differently in this problem.
Think somewhat in this direction
A number 5189 is stored in res[] as following.
res[] = {9, 8, 1, 5}
x = 10
Initialize carry = 0;
i = 0, prod = res[0]*x + carry = 9*10 + 0 = 90.
res[0] = 0, carry = 9
i = 1, prod = res[1]*x + carry = 8*10 + 9 = 89
res[1] = 9, carry = 8
i = 2, prod = res[2]*x + carry = 1*10 + 8 = 18
res[2] = 8, carry = 1
i = 3, prod = res[3]*x + carry = 5*10 + 1 = 51
res[3] = 1, carry = 5
res[4] = carry = 5
res[] = {0, 9, 8, 1, 5}
@Encoder I am not able to understand how the code which you have provided will find the required factorial, Can you please explain in more detail? I have understood why my code won’t work, so, thanks for that.
You want me to elaborate the approach i have discussed ?
If you want to see the explanation of the approach you can watch this video, it would be easy for you to understand it.
@Encoder Thanks! I have understood this solution from the video. Thank you!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.