1. ## Factorial Parsing

Hi I need help writing this program

The factorial, n!, of an integer is defined to be:

n! = ( n * ( n - 1 ) * ( n - 2 ) * ….. * 2 * 1 )

An application of this formula is as follows, 5! = 5 * 4 * 3 * 2 * 1 = 120. This month’s challenge is to find the rightmost non-zero digit of n!. From the above example this number is 2. The rightmost non-zero digit of 12! ( 12! = 479001600 ) is 6.

Write a program that will input an integer between 1 and 14 inclusive and output the rightmost non-zero digit of the factorial. For an added challenge, handle inputs between 1 and 5000 inclusive.

Here are a few test cases for you to try:

Factorial Rightmost Non-Zero Digit
5 - 2
21 - 4
789 - 4
1000 - 2
4013 - 8

thanks for the help

2. Show some code that you have written so far, and point out where you're having trouble, then someone will be able to help you better.

3. ## Re: Factorial Parsing

Originally posted by Joes108
This month’s challenge is to find the rightmost non-zero digit of n!.
Haha, this is clearly some kind of contest or assignment.

But nevertheless:
Code:
```cout << "Input n:";
int n,curr=1;
cin >> n;
for (int c=1; c<=n; ++c)
{
long tmp = c;
while (tmp%5 == 0)
{
tmp/= 5;
curr /=2;
}
curr = (curr % 100000) * tmp;
}
curr%=10;
cout << "Last number: " << curr;```