Leaderboard
Showing:
Last non-zero digit in factorial
Easy Accuracy: 23.81% Submissions: 21 Points: 2

Given a number n, find the last non-zero digit in n!.


Examples:

Input  : n = 5
Output : 2
5! = 5 * 4 * 3 * 2 * 1 = 120
Last non-zero digit in 120 is 2.

Input  : n = 33
Output : 8

Your Task:  
You don't need to read input or print anything. Your task is to complete the function lastNon0Digit() which takes the integer N as input parameters and returns the last non-zero digit in n!.

Expected Time Complexity: O(N^2)
Expected Auxiliary Space: O(1)

 

Constraints:
1 ≤ N ≤ 100

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Last non-zero digit in factorial

Output Window