-3

I have the following code which calculates the number of trailing zeroes in factorial of a number. The program runs for the first testcase which is 10 but when the same code is run for 17 it shows a SIGFPE error in C? Can anyone tell where i am going wrong?

#include<stdio.h>
#include<math.h>
int main(){
    int n,i=1,j,sum=0,l;
    scanf("%d",&n);
    while((n/(5^i))>1)
    {
        j=(n/(5^i));
        i++;
        sum=sum+j;
    }
    printf("%d",sum);
    return 0;
}
Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
Anidh Singh
  • 192
  • 1
  • 6
  • 17

1 Answers1

0

What is wrong is that you are using the operator ^ the wrong way: it is not the power operator, but the bitwise XOR operator. There is no power operator in C, but a pow() function the math library.

On the other way... where the factorial is calculated?

mcleod_ideafix
  • 10,842
  • 2
  • 23
  • 32