 # small factorials..why am i getting wrong answer for my code..? my code is only working for small numbers not for the large ones ..plzz help me out

#include<stdio.h>
int main()
{
unsigned long f=1;
int t,i,j;
scanf("%d",&t);
int n[t];
for(i=0;i<t;i++)
{
scanf("%d",&n[i]);
}
for(i=0;i<t;i++)
{
for(j=1;j<=n[i];j++)
{
f=f*j;
}

``````	printf("%lu\n",f);
f=1;
}
return 0;
``````

}

the answer that you are calculating is out of range of int,long long and unsigned long long …

so… what should i do??? plzzz help…

As the answer is very large,you need to store the number in array(one digit at one index of array )… I suggest you to read this tutorial http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/

Here are couple of hints :

1. Your code is giving WA because you are overshooting the range of long long int.
2. Think how you can store integers with more than 18/19 digits, since no predefined data type in C/C++ can store it.
3. Also think how can you add/multiply such large numbers.

Think of arrays and strings. Good Luck!

Remember the sizes if these data types in c+±>

signed char: -127 to 127 (note, not -128 to 127; this accommodates 1’s-complement platforms)
unsigned char: 0 to 255
char: -127 to 127 or 0 to 255 (depends on default char signedness)
short: 10^5
unsigned short: 10^5
int: 10^5
unsigned int: 0 to 10^5
long: 10^10
unsigned long: 0 to 10^10
long long: 10^18
unsigned long long: 0 to 10^19