-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prime.cxx
51 lines (41 loc) · 987 Bytes
/
Prime.cxx
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
bool Isprime(int i) {
for (int j=2; j<i; j++)
if (i%j == 0) return false;
return true;
};
class Primegenerator {
private:
int a_num{1};
int total_prime_num{0};
public:
/*Primegenerator (int a){
a_num = a ;};*/
int nextprime() {
//int total_prime_num = 0;
a_num++;
while(!Isprime(a_num)){
a_num++;}
total_prime_num++;
return a_num;
//total_prime_num++;
};
int number_of_primes_found() {return total_prime_num;};
int last_number_tested(){return a_num;};
};
int main() {
/*cin >> nprimes;
Primegenerator sequence;
while (sequence.number_of_primes_found()<nprimes) {
int number = sequence.nextprime();
cout << "Number " << number << " is prime" << endl;
}*/
Primegenerator sequence;
for (int count=0; count<10; count++)
cout << "Prime " << count << " is " << sequence.nextprime() << endl;
return 0;
}