can anyone find the logical error in my program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jinnejeevansai
    New Member
    • Nov 2014
    • 48

    can anyone find the logical error in my program

    the question is
    Take a number, x, find its factorial, remove the zeroes, and find the last digit.
    #include<stdio. h>
    #include<math.h >
    int main()
    {
    long long int p,r;
    int m,n,i,j;
    scanf("%d",&m);
    for(i=0;i<m;i++ )
    {
    long long int s=1;
    int count=1;
    scanf("%d",&n);
    if(n==0)
    printf("1\n");
    else
    {
    while(n>0)
    {
    if((n%5)==0)
    {
    count++;
    }
    s=s*n;
    n--;
    }
    p=pow(10,count) ;
    // printf("%lld\n" ,p);
    r=s%p;
    printf("%d\n",r );
    }
    }
    return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What's not working? Use your debugger and step through the code.

    I see a weakness where you use the pow() function because that function uses doubles. An int can be converted to a double but a double cannot be converted to an int due to loss of the decimal places. So the return value cannot be reliable assigned to an int.

    Comment

    Working...