-1

i've made my code to solve a puzzle at http://www.codechef.com/problems/FCTRL

According to what i've tested, the program works right for any string of number. Apparently, the CodeChef website reports a wrong output.

Can anyone correct me on this?

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;
}
rajagrawal
  • 622
  • 4
  • 14
  • 26
  • 1
    First of all, what is the expected output for some specified input, and what is the actual output? Second, this should be on http://codereview.stackexchange.com/. – Some programmer dude Jan 21 '13 at 06:40
  • My apologies. I'll keep that in mind. The bold text is the output for each input. The website has a rule that in such puzzles, the output should be one after the other input and not as a accepting all inputs at once and throwing out all output at once. Hence, this: 8 4 **0** 5 **1** 25 **6** 100 **25** 1000 **254** 100000 **25053** 9999999 **2505045** 999999999 **250505035** – rajagrawal Jan 21 '13 at 06:48

1 Answers1

3

victim3 is never initialized... so it could start at any value.

You should likely initialize victim3 to be 0.

abelenky
  • 63,815
  • 23
  • 109
  • 159
  • That did the job. I forgot the fact that in C, the default values for variables are initialized to garbage. Thanks! – rajagrawal Jan 21 '13 at 07:19
  • More accurately, they are not initialized at all. Their starting value is whatever happens to be left over in that memory location from whatever was there before. – abelenky Jan 21 '13 at 14:39