我正在练习一些书本问题,但我无法理解为什么会出现“由于信号而终止:浮点异常(8)”错误。
如果可能,您能否解释一下为什么会出现错误以及如何修复它。
感谢您的时间。
我不明白这个错误。因此,我没有尝试任何东西
#include <iostream>
using namespace std;
const int ARR_LENGTH =11;
int main() {
int arr[ARR_LENGTH] = {2,3,5,7,11,13,17,19,23,29};
int input =0;
bool isItRight;
bool isItPrime;
cout <<"Input an integer between 1 and 1000" <<endl;
while (isItRight == false){
cin >>input;
if (!(1000 >=input && input >= 1))
isItRight = false;
else
isItRight =true;
if (input<1 || input > 1000 ){
cout <<"Input out of range" <<endl;
cout << "enter a new value: ";
} else if (!input){
cout <<"wrong data type, enter a new value: ";
}
}
for (int i =0; i < ARR_LENGTH; i++){
if (input % arr[i] || input == arr[i])
isItPrime =true;
else
isItPrime =false;
}
if (isItPrime == true){
cout <<"\nThe value "<<input <<" is prime!" <<endl;
} else if (isItPrime == false){
int i =0;
while (i< ARR_LENGTH){
if ((input % arr[i]) == 0 ){
cout <<"\nThe value "<<input <<" is divisible by: "
<< arr[i] <<endl;
}
}
}
return 0;
}
我希望检查质数,并且使用适当的策略我无法输出任何内容。