-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
  • 378,754
  • 76
  • 643
  • 1,055
Anidh Singh
  • 302
  • 2
  • 7
  • 19

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
  • 11,128
  • 2
  • 24
  • 32