我正在尝试获取前 10 个素数,但在编译时出现浮点异常(核心转储)错误。
#include <stdio.h>
#define MAX 50
int main(void){
FILE * fp;
int i,j,cnt=0;
int prim[MAX]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
fp = fopen("primeros.dat", "wb");
do{
for (i=2; i<=100; i++){
for(j=0;j<=MAX;j++){
if (i%prim[j]==0){
continue;
}
else{
fwrite(&i, sizeof(int), 1, fp);
cnt++;
}
}
}
}while(cnt<10);
fclose(fp);
return 0;
}