# Prime Number Practice

```#include <iostream>

using namespace std;

const int scope = 2000;

void SetScope(int scope[], int length);

// this program print prime number in scope 1 to 2000
int main(void) {
int targetNumberScope[scope + 1];

SetScope(targetNumberScope, scope);

exit(EXIT_SUCCESS);
}

void SetScope(int scope[], int length) {
for (int i = 0; i < length; i++)
scope[i] = true;
}

void CalculatePrimeNumber(int scope[], int length) {
for (int masterIter = 2; masterIter < length; masterIter++) {
if (scope[masterIter]) {
for (int i = 2, secondIter = masterIter * i; secondIter < length; secondIter = masterIter * ++i) {
if (scope[secondIter])
scope[secondIter] = false;
}
}
}
}

void PrintPrimeNumber(int scope[], int length) {
for (int i = 1; i < length; i++) {
if (scope[i])
cout << i << " | ";
}
}
```

Java 로 연습
```public class PrimeNumberTest {

static final int SCOPE = 2000;

private static boolean numberPool[];

private static void InitializeNumberPool() {
numberPool = new boolean[SCOPE + 1];
for (int i = 0; i <= SCOPE; i++)
numberPool[i] = true;
}

for (int i = 2; i <= SCOPE; i++) {
if (numberPool[i])
for (int j = i, k = 2; j * k <= SCOPE; k++)
numberPool[j * k] = false;
}
}

private static void PrintResult() {
for (int i = 1; i <= SCOPE; i++)
if (numberPool[i])
System.out.print(i + " -> ");
}

public static void main(String[] args) {
InitializeNumberPool();