CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cmath>
using namespace std;
int main() {
unsigned int howMany = 1000;
unsigned int *primesArr = NULL;
primesArr = new unsigned int[howMany]; // number of primes to calculate
primesArr[0] = 2; primesArr[1] = 3; // initial values for an array
bool isPrimary;
unsigned int i = 1;
while (i < howMany) {
isPrimary = true;
unsigned int j = 1;
while (primesArr[j] <= ceil(sqrt(primesArr[i]))) {
if (primesArr[i]%primesArr[j] == 0) {
isPrimary = false;
break;
}
j++;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run