mardi 22 décembre 2020

How to fix "Program terminated with signal SIGFPE"

The question is :-

Given an integer, for each digit that makes up the integer determine whether it is a divisor. Count the number of divisors occurring within the integer.

Complete the findDigits function in the editor below.

findDigits has the following parameter(s):

int n: the value to analyze

int findDigits(int n) {
   vector<int> digits;
   int temp = n;
   int result = 0;
   while(temp!=0){
       digits.push_back(temp%10);
       temp/=10;
   }
   for(int i=0 ; i<digits.size() ; i++){
       int s = digits[i];
       if(n % s == 0){
           result ++;
       }
   }
   return result;
}

The error I got is :

Reading symbols from Solution...done.

[New LWP 769213]

[Thread debugging using libthread_db enabled]

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Core was generated by `./Solution'.

Program terminated with signal SIGFPE, Arithmetic exception.

#0  0x0000000000401433 in findDigits (n=1012) at Solution.cpp:16

16          if(n % s == 0){

To enable execution of this file add

    add-auto-load-safe-path /usr/local/lib64/libstdc++.so.6.0.25-gdb.py

line to your configuration file "//.gdbinit".

To completely disable this security protection add

    set auto-load safe-path /

line to your configuration file "//.gdbinit".

For more information about this security protection see the

"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:

    info "(gdb)Auto-loading safe path"

Aucun commentaire:

Enregistrer un commentaire