Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- void eratosfen (int *arr, int n)
- {
- int p = 0;
- for (int p = 2; p < n + 1; p++)
- {
- if (arr[p] != 0)
- {
- cout << arr[p] << " ";
- for (int j = p*p; j < n + 1; j += p)
- arr[j] = 0;
- }
- }
- }
- int main()
- {
- int n = 0;
- cin >> n;
- int *arr = new int[n+1];
- for (int i = 0; i < n + 1; i++)
- {
- arr[i] = i;
- cout << arr[i] << " ";
- }
- cout << endl;
- eratosfen(arr, n+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement