forked from 2unaa/Intro-to-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRE7.cpp
More file actions
43 lines (36 loc) · 593 Bytes
/
RE7.cpp
File metadata and controls
43 lines (36 loc) · 593 Bytes
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
#include <iostream>
using namespace std;
int isPrime();
int main()
{
int counter;
counter = isPrime();
cout << endl << "There are " << counter << " numbers between 2 and 1000" << endl;
return 0;
}
int isPrime()
{
bool prime = true;
int counter = 0;
for(int i = 2; i <= 1000; i++)
{
for(int n = 2; n<= i/2; n++)
{
if(i % n == 0)
{
prime = false;
}
}
if(prime == true)
{
cout << i << " " ;
counter++;
if(counter % 10 == 0)
{
cout << endl;
}
}
prime = true;
}
return counter;
}