我正在尝试使用筛子打印出一组特定的素数,但我似乎没有得到任何输出,但它编译得很好。除非我强迫它,否则程序不会退出,所以我猜它卡在某个地方......我该如何解决这个问题?
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int64_t* prime_vector(int64_t start);
int64_t* prime_vector(int64_t start) {
int64_t* vector = calloc(7,sizeof(int64_t));
int64_t maxnum = 2000000;
int64_t *isprime = calloc(maxnum, sizeof(int64_t));
for (int i=0; i < maxnum; i++){
isprime[i] = 1;
}
for (int64_t i=0; i*i < maxnum; i++){
if (isprime[i]){
for (int64_t j = i*i; j<maxnum; j+=i){
isprime[j] =0;
}
}
}
int64_t count = 0;
int64_t max = 7;
int64_t number = start;
int64_t j = 0;
for (int64_t i = number; i<maxnum;i++){
if (count < max && isprime[i]){
vector[j] = i;
count++;
j++;
}
}
free(isprime);
return vector;
}
int main (void){
int64_t* array = prime_vector(13);
for (int i=0; i<7; i++){
printf("%d\n",array[i]);
}
return 0;
}