Question

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;
}
Was it helpful?

Solution

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

You should likely initialize victim3 to be 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top