# FCTRL2 Doubt

Can someone explain me the difference between

``````for(i=1;i<=n;i++)
{

x=a[0]*i+temp;
a[0]=x%10;
temp=x/10;
}

**AND**

for(i=1;i<=n;i++)
{

for(j=0;j<m;j++)
{
x=a[j]*i+temp;
a[j]=x%10;
temp=x/10;
}
}
``````

Even though a[j]is always a[0] since value of j doesnt exceed 0 as m is always 1.Why do these codes work differently? Or did I understand something wrong.Any help is appreciated.

you might initialing temp with different value or taking value of m>1 other than there is no error in you code

bro , what are you talking about , how can someone know what have u written previously.

Factorial of 100! contains a lots of digits(93, 326, 215, 443, 944, 152, 681, 699, 238, 856, 266, 700, 490, 715, 968, 264, 381, 621, 468, 592, 963, 895, 217, 599, 993, 229, 915, 608, 941, 463, 976, 156, 518, 286, 253, 697, 920, 827, 223, 758, 251, 185, 210, 916, 864, 000, 000, 000, 000, 000, 000, 000, 000)you can count it yourself!!

there is no data type particularly in cpp which can hold such a big digit.

here is what you can do

declare an array of at most 200 integers and then perform multiplication method like we did in our 4th or 5th class.

for example 120 X 6

first multiply 6 to 0 ans comes out be 0 put 0 in first element of another array then multiply 6 to 2 ans comes out to be 12 put 2 in the second element of array and keep 1 aside for a moment. then multiply 6 to 1 ans comes out be to be 6 add 1 to it, it became 7 and then put 7 in the third element.

in this way you can find the value of 100!.

HOPE YOU GOT IT!!

I initialized temp with 0 and m is also 1.For both the cases,Im using similar parameters except for the fact that the first case gets me a wrong answer while the second case works.

Please give complete code for these problems. In C++, we need that to rule out undefined behavior and uninitialized variables which cause these issues commonly.