The reason it's in a function is because I'm writing all the algorithms in the same program, and I want to separate it a bit.
Code: Select all
#include <iostream>
using namespace std;
void prime_one();
int main()
{
prime_one();
return 0;
}
void prime_one()
{
const int MAX = 1000;
bool prim;
for(int i = 2; i <= MAX; ++i)
{
prim = true;
for(int j = 2; j <= i && prim == true; ++j)
{
if(j < i && i % j == 0)
prim = false;
}
if(prim == true)
cout << i << " is a prime number\n";
else
cout << i << " is NOT a prime number\n";
}
}