0
I'm trying to make function that generates prime from range [n, 3n] but it's not working and I don't know why..
1 Answer
+ 3
Indexing problem perhaps is the first thing you need to address. You see, you created a boolean array <S> with <n> + 1 elements.
cin >> n;
S = new bool[n + 1];
Then here comes the problem, you iterate the array starting from index <n> up to 3 * <n>
for(i = n; i <= 3 * n; i++) S[i] = true;
But the array only have <n> + 1 elements reserved, An attempt to iterate the array outside its boundary crashed the code.