small factorial wrong answer

please tell me in which case it fails,it always shows wrong answer but when i compiled it in my compiler it ran successfully for any number.

#include<stdio.h>
int main()

{int x,a[200]={0},i,j,k,m,n,b,temp;

scanf("%d",&n);

while(n–)

{scanf("%d",&b);

a[0]=1;

m=1;

for(i=2;i<=b;i++)

{temp=0;

for(j=0;j<m;j++)

{x=a[j]*i+temp;

a[j]=x%10;

temp=x/10;

}

while(temp!=0)

{a[m++]=temp%10;

temp=temp/10;

}

}

for(k=m-1;k>=0;k–)

printf("%d",&a[k]);

}

return 0;

}

Check here: https://ideone.com/MADngZ

Your program is giving wrong answer for the sample test cases itself.

2 Likes