Your code does not hold water. Here is the simplest code that computes prime numbers. The algorithm is terribly inefficient, but it works.
#include <vector> #include <iostream> int main() { const unsigned max = 100; std::vector<unsigned> simple; for (unsigned n = 2; n <= max; ++n) { bool isSimple = true; for (size_t i = 0; i < simple.size(); ++i) { if (n % simple[i] == 0) { isSimple = false; break; } } if (isSimple) { simple.push_back(n); std::cout << n << std::endl; } } }
PS Inefficiency, by the way, is relative. This algorithm applies to memory almost as economically as possible, but the speed of work leaves much to be desired. However, prime numbers up to a million calculates in less than a minute.
numerics
? - ixSci