smallfactorial

plz help me out…it shows garbage value
#include
using namespace std;

int main()
{

int i,j,k,fact,a[200];
int m=0,n,temp,x,z,p;
cin>>i;
while(i>0 && i<=100)
{
    cin>>n;
    j=n;

    if(n>0 && n<=100)
    { 

`` while(j!=0)
{

           x=j%10;
           a[m]=x;
           j=j/10;
           m++;
       }

       for(i=n-1;i>0;i--)
       {
           for(p=0;p<m;p++)
           {
               z=(i*a[p])+temp;
               a[p]=z%10;
               temp=z/10;
           }
            while(temp!=0)
            {
               a[m]=temp%10;
               temp=temp/10;
               m++;
            }
       }

       for(p=0;p<m;p++)
        cout<<a[p];
       cout<<"\n";
    }
    i--;
}
return 0;

}

It is because you are storing number of test cases in the variable named ‘i’ and then changing it’s value in one of the for loops. Just change the for loop into for(int i = n-1; and so on). Also you may get wrong output from the above code (you may have to change the way you display). I think you may want to try on that one. This should fix your problem of garbage value. If you still don’t get it right you can ask…

Happy coding :slight_smile: