Small Factorial Run time error SIGSEGV

My solution:

#include<iostream>
using namespace std;
#define MAX 160
int a[MAX];
int main()
{
int n,j,x,index,temp,i;
a[0]=1;
index=0;
cin>>x;
for(j=1;j<=x;j++)
{
cin>>n;
for(;n>=2;n--)
{
temp=0;
for(i=0;i<=index;i++)
{ 
temp=(a[i]*n)+temp;
a[i]=temp%10;
temp=temp/10;
}
while(temp>0)
{
a[++index]=temp%10;
temp=temp/10;
}
}
for(i=index;i>=0;i--)
cout<<a[i];
}
return 0;
}

Not able to correct the run time error . Can you help me out?

Link to the statement for convenience. http://www.codechef.com/problems/FCTRL2

//