Hello…
I am doing this question from GFG…
Name - Last non-zero digit in factorial
Question Link-- https://practice.geeksforgeeks.org/problems/last-non-zero-digit-in-factorial/0
This is my solution…
https://ide.codingblocks.com/s/330481
This code is showing wrong answer for some test case…
I am not able to find…where it is wrong…
Please help me…
Not able to solve
1).Here first i have taken n
2).Now i multipled it by k(which is 1 intially ) and stored it in kk.
3)Now i have taken the last non-zero value of kk and updated the value of k to the kk%10
4).Now i have decreased the value of n by one
5).Called again function on n-1 and k.
It is showing rigth for some and wrong for some other…
Please have a look at this image…
2).Now i multipled it by k(which is 1 intially ) and stored it in kk.
3)Now i have taken the last non-zero value of kk and updated the value of k to the kk%10
4).Now i have decreased the value of n by one
5).Called again function on n-1 and k.
It is showing rigth for some and wrong for some other…
Please have a look at this image…
ok so basically u r trying to keep track of left most non zero digit while computing factorial right?
Yes…
But this is not showing rigth output always…
Can you suggest me why??
the technique works if we need to find the left most digit.
here we are discarding some zeros may thats why it is not working for all test cases.
pls refer this->
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.

