#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
char arr[200],res[200];
char table[150][200];
string multiply(char n[],int m)
{
int N=strlen(n),M,temp=0,x=0;
for(int i=0;i<N;i++)
arr[i]=n[N-1-i];
for(int i=0;i<N;i++)
{
x=m*(arr[i]-'0')+temp;
x=m*(arr[i]-'0')+temp;
arr[i]=(x%10)+'0';
temp=x/10;
}
while(temp>0)
{
arr[N]=(temp%10)+'0';
temp/=10;
N++;
}
M=strlen(arr);
for(int i=0;i<M;i++)
res[i]=arr[M-1-i];
}
void make_table()
{
table[0][0]='1';
for(int i=1;i<101;i++)
{
multiply(table[i-1],i);
int u=strlen(res);
for(int j=0;j<u;j++)
{
table[i][j]=res[j];
}
}
}
int main()
{
int tc,n;
scanf(" %d",&tc);
make_table();
while(tc--)
{
scanf(" %d",&n);
printf("%s\n",&table[n]);
}
return 0;
}
That's my code for this problem : http://www.spoj.pl/problems/FCTRL2/ It generates correct answers for me but when i submit it , it tells me Runtime error(segmentation fault) . Can anyone explain to me what is the segmentation fault? cause i read it on the spoj website and i didn't understand how to avoid it and how to upgrade my code?