# can anyone tell why my solution encounters a run time error, despite it runs fine on my system?

Question ishttp://www.codechef.com/problems/FCTRL2
Solution— http://www.codechef.com/viewsolution/1760788
Here i have copied it ----------------------------------------------------------------------------

``````#include<iostream>
#include<malloc.h>
#define MAX_SIZE 80
using namespace std;

int current;
void proMul(int* a, int num)
{
int tempc=0;
int temp=0;
while(tempc<=(current-1))
{
int x= (*(a+tempc)*num)+temp;

*(a+tempc)= x%10;
temp= x/10;
tempc++;

}
tempc--;

while(temp>0)
{
tempc++;
*(a+tempc) = temp%10;
temp/=10;
}
current = tempc+1;

}

void printa(int* ans)
{
int temp= current-1;
while(temp>=0)
{
cout<<*(ans+temp);
temp--;
}
cout<<endl;

}

void fac(int num)
{
//  int ans[MAX_SIZE]={0};
int i;
int* ans= (int*) (malloc(MAX_SIZE* sizeof(int)));
for(i=0;i<MAX_SIZE;i++)
*(ans+i) = 0;
*ans= 1;
current=1;
while(num>1)
{           proMul(ans, num);
num--;
}
printa(ans);

}

int main()
{
int T;
cin>>T;
int x;
while(T--)
{
cin>>x;
fac(x);

}
return 0;
}``````

on ideone (http://ideone.com/StqIb0) it also failed with input

``````3
100
100
100
``````

@betlista, yeah, but it however runs for the the first two inputs, and then encounters run time error, however the same problem doesn’t arise for small numbers. I can’t find the error.

//