FACTORIAL - submission issue (C Program)

According to what i’ve tested, the program works right, even for 7 digit numbers. But, CodeChef’s compiler reports ‘Wrong Answer’. Can anyone correct me?

Here’s what I coded:

#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,iterations,target,victim1,victim2,victim3;
    
    scanf("%d",&iterations); //take the number of acceptable iterations.

    for(i=0;i<iterations;i++)
        
    {
        scanf("%d", &target); //take the number as a target input the user want's to calculate on.

        victim1=target/5;
        
        victim2=victim1;
        
        while(victim1>=5)
            
        {
            victim1=(victim1)/5;
            
            
            victim3=victim3+victim1;
            
        }
        
        printf("%d\n",victim2+victim3);
        
    }
    
    return 0;
}

Please give me link to that problem. I am not clear ,for which problem do you have wrote this code?

I realised my error. Turns out the compiler i’m using, doesn’t mind having calculations on and with un-initialised variables. While a GCC compiler does (used at CodeChef). I missed initialising victim3 to 0 and that went unnoticed.

Thanks for your time maheshksd :slight_smile:

1 Like
//