# Small factorial (in practice - easy)

#include<stdio.h>
#define max 150
int arr[max],length=1;
factorial(int);
main()
{
int T=0 ,n=0,i=0,j=0,k=0;
int temp,x;
int out[150];
scanf("%d",&T);

``````arr[0] = 1;
for(i=0;i<T;i++)
{
scanf("%d",&n);
factorial(n);

for(j=length-1;j>=0;j--)
{
out[k] = arr[j];
k++;
}

out[k] = 100;
k++;
arr[0]=1;

for(j=length-1;j>0;j--)
{

arr[j]=0;
}
length=1;

}

for(j=0;j<k;j++)
{
if(out[j]==100)
{
printf("\n");
}
else
printf("%d",out[j]);
}
``````

}
factorial(int n)
{
int i,j,x,temp=0;
for(i=2;i<=n;i++)
{
for(j=0;j<length;j++)
{
x= arr[j]* i + temp;
arr[j] = x%10;
temp = x/10;

``````    }
if(temp !=0)
{
while(temp!=0)
{
length++;
arr[j] = temp%10;
temp = temp /10 ;
j++;
}

}

}
``````

}

my code works fine for even 400! but im getting and error of “Runtime Error(SIGSEGV)” while submmitting the answer can anybody plz help me out here and tell me what to be corrected ? …

I guess, 100! will need more than 150 digits… Try increasing the array size…

I don’t think so your code would be able to provide an output of 400! or even 100!.

See this :

Just observe this pic length of 100! is of 158 decimal numbers,

and as you are saying about 400!, its length is 869…

So there will definitely be a segmentation fault [SIGSEGV] as you have defined the array of MAXSIZE 150.