# Help to get desired form of output

 Akhilesh Chobey · November 25, 2015 I am writing a code to find number of zeroes in the factorial of a number.It prints the answer on separate lines in each loop.For e.g 1024! (factorial) has 255 zerosSo it prints 204,40,8,1.How do I print the addition of these instead of multiple lines of answer.ThanksMy code :#include #include #includeint main(){int n;printf("Enter the number:\n");scanf("%d", &n);int numberOfZeros;int i;for(i=1;i<200;i++){if(pow(5,i)

## Replies

 Dan P · November 25, 2015 Hi Akhilesh,Change this line, numberOfZeros=n/(pow(5,i)); tonumberOfZeros = numberOfZeros + (n/(pow(5,i)));ornumberOfZeros += n/(pow(5,i));and then move the printf outside of the for loop. Akhilesh Chobey · November 25, 2015 Hey Dan, Thanks for your reply.I made the changes you said:#include #include #includeint main(){    int n;    printf("Enter the number:\n");    scanf("%d", &n);    int numberOfZeros;    int i;    for(i=1;i<200;i++){    if(pow(5,i) 0;n--){                nfac *= n;        }        numOfzeros = countNumberOfZeros(nfac);        printf("Result: %d\n Number of zeros: %d\n", nfac, numOfzeros);        return 0;}int countNumberOfZeros(int result) {        char buffer[32];        int numberOfZeros = 0;        int i;        snprintf(buffer, 32, "%d", result);        for(i = 0; buffer[i] != '\0'; i++) {                if(!(strncmp(&buffer[i], "0", 1))) {                        numberOfZeros++;                }        }        return numberOfZeros;}``This does what you want.Although it is very limited, see if you can see why it's limited and come up with a solution on how to fix that? Akhilesh Chobey · November 25, 2015 Okay. It will take me a while to interpret the code as I am still a newbie and also not acquainted with some of the syntax which you have used.Anyways. Thanks for your help.
• 1

## C

120,935 followers