修改完RE (SIGSEGV)問題後 又出現SE () 程式終止:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
int iary[19999] ;
string sary[19999];
int counter = 0;
for(int i=0;i<19999;++i){
iary[i]=0;
sary[i]="質數";
}
while(cin>>iary[counter]){
if(iary[counter]>=2&&iary[counter]<=2147483647){
if(iary[counter]==2||iary[counter]==3||iary[counter]==5||iary[counter]==7){
sary[counter]="質數";
}else{
if((iary[counter]>2)&(iary[counter]%2==0)){
sary[counter]="非質數";
}else{
for(int i=3;i<=sqrt(iary[counter]);i+=2){
if( iary[counter]==3){
sary[counter]="質數";
break;
}
if(iary[counter]%i==0){
sary[counter]="非質數";
break;
}
}
}
}
}else{
sary[counter]="非質數";
}
++counter;
if(counter==19999){
break;
}
}
for(int i=0;i<counter;++i){
cout<<sary[i]<<'\n';
}
return 0;
}
想請求協助 thanks'