-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimes.cpp
More file actions
49 lines (43 loc) · 953 Bytes
/
primes.cpp
File metadata and controls
49 lines (43 loc) · 953 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
42
43
44
45
46
47
48
49
#define PROGNAME "primes"
#include <iostream>
using namespace std;
int
main(int argc, char * argv[])
{
int max, Number, i, count = 0;
if(argc < 2)
{
cerr << endl
<< " I need a max number" << endl
<< " like this: $ " << PROGNAME << " 123" << endl
<< endl;
return EXIT_FAILURE;
}
max = atoi(argv[1]);
if(max < 1)
{
cerr << "think positive" << endl;
return EXIT_FAILURE;
}
cout << "1, ";
for(Number = 2; Number <= max; Number++)
{
for(i = 2; i <= Number / 2; i++)
{
if(Number % i == 0)
{
count++;
break;
}
}
if(!count)
{
cout << Number << ", ";
}/*else
{
cout << Number << " is Not" << endl;
}*/
count = 0;
}
cout << "max reached" << endl;
}