I'm trying to make function that generates prime from range [n, 3n] but it's not working and I don't know why.. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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..

https://code.sololearn.com/cBx73Gudr3j3/?ref=app

8th Dec 2022, 1:06 PM
Kamil Chojnacki
Kamil Chojnacki - avatar
1 Respuesta
+ 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.
8th Dec 2022, 1:44 PM
Ipang