Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int index = 1;
- int* eratosthenesArray;
- const int sizeOfArray = 20;
- void Init()
- {
- eratosthenesArray = new int[sizeOfArray];
- for (int i = 0; i < sizeOfArray; i++)
- {
- eratosthenesArray[i] = i + 1;
- }
- }
- void EratosthenesAlgorithm()
- {
- for (int i = index; i < sizeOfArray; i++)
- {
- if (index != i &&
- eratosthenesArray[index] != 0 &&
- eratosthenesArray[i] % eratosthenesArray[index] == 0)
- {
- eratosthenesArray[i] = 0;
- }
- }
- index++;
- /*if (index < sizeOfArray)
- {
- EratosthenesAlgorithm();
- }*/
- }
- void Print()
- {
- for (int i = 0; i < sizeOfArray; i++)
- {
- cout << eratosthenesArray[i] << " ";
- }
- cout << endl;
- }
- int main()
- {
- Init();
- Print();
- while (true)
- {
- if (index >= sizeOfArray)
- {
- break;
- }
- EratosthenesAlgorithm();
- }
- Print();
- delete[]eratosthenesArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement