small factorial...wrong ans

i dont know the cases where it fails but i have checked it even for 100 and other smaller numbers it is showing the correct ans but when i try to submit it everytime showing wrong ans dont know why .
somebody pls help you can chk the following code yourself in your compiler.
**I KNOW THE CODE IS A BIT COMPLEX.MAY BE THERE IS A BETTER WAY TO SOLVE THE SAME QUESTION BUT I AM NOT GETTING THAT CASE ON WHICH IT FAILS SO PLS HELP. **
#include<stdio.h>

int g(int c);

int main()

{int a,x,k,te,b,z,m,j,e,c,d,i,t;

int f[1000];

scanf("%d",&a);

for(i=0;i<a;i++)

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

k=t;

d=g(t);

for(b=0;b<d;b++)

 { f[b]=t%10;

   t=t/10;

 }

te=0;

m=0;

x=0;

if(k>1)

{

while(–k)

{ while(d--)

{

  x=f[m]*k+te;

  f[m]=x%10;

  te=x/10;

  m++;

  }

 while(te)

{

 f[m]=te%10;

 te=te/10;

 m++;

 }

   d=m;

 e=m-1;

 m=0;

 te=0;

 }

for(j=e;j>=0;j--)

{printf("%d",f[j]);}

printf("\n");

}if(k==1)

printf("1");

}

return 0;}

int g(int c)

{int a=0;

while©

{a=a+1;

c=c/10;

}

return a;}

Please post your code properly using proper blocks or ideone code is always better. :slight_smile:

1 Like

Check here: [https://ideone.com/CwES8i][1]

The output formatting is wrong.
[1]: https://ideone.com/CwES8i

2 Likes