Prime Numbers 2 - 1000
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int array_size = 1000;
bool num[ array_size ];
for ( int a = 2; a < array_size; a++ ) // Set all elements to 1
{
num[ a ] = 1;
}
for ( int b = 2; b < array_size / 2; b++ )
{
if ( num[ b ] == 1 )
{
for ( int c = b; c < array_size; c + b )
{
num[ c ] = 0;
}
}
}
for ( int d = 2; d < array_size; d++ )
{
if ( num[ d ] == 1 )
{
cout << d << endl;
}
}
cin.get();
return 0;
}
No output.
Maybe the fact that it's 2 am whenever I try to do a question in the book doesn't help.