Small factorial:can anyone tell whats the problem in my code??it is showing wrong answer on submitting.

Problem code: FCTRL2 i have made the solution in java but yet it is giving wrong answer on submitting and when i m running its giving ryt answer please help me out . i have pasted the code below.

import java.io.*;

class solution{
public static void main(String args[]) throws

IOException
{
BufferedReader br = new BufferedReader(new

InputStreamReader(System.in));
int[] a=new int[200];
int i=0,m=0,temp=0;
int T=Integer.parseInt(br.readLine());
if(T>100)
{
System.exit(0);
}

while(T>0){
int n=Integer.parseInt(br.readLine());
if(n>100)
{
System.exit(0);
}
int n1=n;
if(n<100){
a[i]=n;
m++;
i++;
}
else{
while(n>0)
{
a[i]=n%10;
m++;
i++;
n=n/10;
}
}
for(int j=n1-1;j>0;j–)
{
i=0;
while(i<m)
{
int x=a[i]*j+temp;
temp=x/10;
a[i]=x%10;
i++;
}
while(temp>0)
{
m++;
a[i]=temp%10;
temp=temp/10;
i++;
}
}
while(m>0)
{
System.out.print(a[–m]);
}
System.out.println();
T=T-1;
}
}
}

its unreadble…please give the link to the solution

link:-

http://www.codechef.com/viewsolution/5613867

For every test case, make i equal to 0 in the beginning. Else, when the statement a[i] = n executes, it takes i value from the previous iteration which probably would be size of previous answer. Make this change…

while(T > 0)
{
    i = 0;
    //rest of the code
    T = T-1;
}

hey thanks vinayawsm,
my code accepted silly mistake by me
thanks a lot!!

you are welcome :slight_smile: