Here’s my code in C for Small Factorials problem in the Easy section of Practice problems. The code runs correctly for the sample test cases given, but when I submit it, I get wrong answer. Why is this happening? Please help me.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, n, *p, *q;
scanf("%d", &n);
p = (int *)malloc(n*sizeof(int));
q=p;
for(i=0; i<n; i++)
{
scanf("%d", &p[i]);
}
for(i=0; i<n; i++)
{
long fact=1;
int m = p[i];
while(m != 1)
{
fact = fact * m;
m--;
}
printf("%ld\n", fact);
}
free (q);
return 0;
}