如何解决如何修复“程序因信号 SIGFPE 终止”
问题是:-
给定一个整数,对于组成该整数的每个数字,确定它是否是一个除数。计算整数中出现的除数的数量。
在下面的编辑器中完成 findDigits
函数。
findDigits
具有以下参数:
int n:要分析的值
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;
}
我得到的错误是:
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"
解决方法
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(s != 0) //---//
if(n % s == 0)
result ++;
}
return result;
}
这是一个运行时错误,s
的值在某些时候可能是 0
,因此您正面临这些错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。