floating point exception in c program -



floating point exception in c program -

while running code getting floating point exception pls explain why coming so.

#include <stdio.h> int gcd(long int, int); int main() { int t, n, a, i; long int abc; scanf("%d", &t); while (t--) { abc = 1; scanf("%d", &n); abc = n * (n - 1); (i = n - 2; > 1; i--) { = gcd(abc, i); abc = ((abc * i) / a); } printf("%ld \n", abc); } homecoming 0; } int gcd(long int a, int b) { if (b == 0) homecoming a; else { homecoming (b, % b); } }

the else part in gcd function bogus. wanted phone call gcd recursively , instead returning a % b. , result if a % b == 0 split 0 on line 13.

the look (b, % b) evaluated 2 subexpressions separated comma operator. value of b forgotten , value of whole look becomes a % b.

the right version:

int gcd(long int a, int b) { if (b == 0) homecoming a; else { homecoming gcd(b, % b); } }

c exception floating-point

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -