Hello all!
I have a task to code a program that would find the last non-zero digit of the factorial of a given number n where 1<n<10000
so far i got this:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int a, xxx;
unsigned long long b=1;
string x;
stringstream buf;
cin>>a;
for(int i=2; i<=a; i++)
{
b=b*i;
while(b%10==0){
b=b/10;
}
}
buf<<b;
buf>>x;cout<<x[x.length()-1];
system("pause");
return 0;
}
The problem is that i cannot store the factorials of bigger numbers, and i find using arrays a little too complicated. Any help is greatly appreciated.
Regards, FREEZX