Why wrong answer? Works fine for all values on dev c++

#include<stdio.h>

int main()
{ int i,t;
int a[100];
double q;
double factorial(int m);
scanf("%d",&t);
for(i=0;i<t;i++)
{ scanf("d",&a[i]); } for(i=0;i<t;i++) { q=factorial(a[i]); printf("-2.0lf\n",q);
}
return 0;
}
double factorial(int m)
{
double f=1;
int j;
for(j=1;j<=m;j++)
{ f=f*j;
}
return f;
}

check this http://discuss.codechef.com/questions/43872/getting-wrong-answer-in-small-factorial