I have to writea piece of code to calculate the factorial of somewhat large numbers so the long long type won't suffize, so using vector, I stumbled upon some issues during run time:
'#include
#include
using namespace std;
vector factorial(short n)
{
vector v, z;
do
{
short m = n%10;
v.push_back(m);
}while(n/=10);
short temp = 0;
int x;
//short m = 0;
while(n-1)
{
for(auto &w : v)
{
x = w*(n-1) + temp;
temp = x/10;
z.push_back(x%10);
}
}
return z;
}
int main()
{
short T;
cin >> T;
vector v;
short temp;
while(T--)
{
cin >> temp;
v.push_back(temp);
}
vector tmp;
for(auto &w : v)
{
tmp = factorial(w);
for(auto i=tmp.end(); i!=tmp.begin(); i--)
cout << *i;
cout << endl;
}
return 0;
}
'