Back. Noob as always. Had to take a long break due to school. Anyway, I wrote a simple program for spitting out prime numbers up to a number n (its value is hard-coded). Unfortunately, when I run the program in MinGW, it crashes if the value of n is greater than 260269. Which is weird. The cause is either a poor compiler (I doubt the GCC is so shitty) or it's because my code is so shitty that it simply can't handle such an unoptimized way of crunching numbers. Even so, I still think it's weird. Here is the program:
#include <iostream>
#include <cmath>
usingnamespace std;
int main() {
int c, i, n = 260296, x, primes[n];
bool flag = true;
for (i = 1; i < n; i++)
primes[i] = 0;
primes[0] = 2;
c = 0;
i = 0;
x = 3;
while (x <= n) {
do {
if (x % primes[i] == 0)
{
flag = false;
break;
}
i++;
} while ( primes[i] <= sqrt(x) && primes[i] != 0);
if (flag) {
c++;
primes[c] = x;
}
else
flag = true;
i = 0;
x++;
}
for (i = 0; primes[i] != 0; i++)
cout << primes[i] << "\n";
}