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