Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
sieve.cpp
Go to the documentation of this file.
1
29#include <vector>
30#include <iostream>
31
32#include <examples.h>
33
34int main ()
35{
36
37 std::cout << "Prime Sieve program, a test of vectors" << std::endl;
38
39 // Create a sieve of bits, initially set to 1.
40 const int sievesize = 100;
41 std::vector<int, std::allocator<int> > sieve ((std::size_t)sievesize, 1);
42
43 // At positions that are multiples of i, set value to zero.
44 for (int i = 2; i * i < sievesize; i++)
45 if (sieve[i])
46 for (int j = i + i; j < sievesize; j += i)
47 sieve[j] = 0;
48
49 // Now output all the values that are still set.
50 for (int j = 2; j < sievesize; j++)
51 if (sieve[j])
52 std::cout << j << " ";
53
54 std::cout << std::endl << "End of Prime Sieve program" << std::endl;
55
56 return 0;
57}
#define i
Definition 17.names.cpp:126
#define j
Definition 17.names.cpp:127
int main()
Definition sieve.cpp:34