diff --git a/C++/sieve/yathansh.cpp b/C++/sieve/yathansh.cpp new file mode 100644 index 0000000..3b656cc --- /dev/null +++ b/C++/sieve/yathansh.cpp @@ -0,0 +1,29 @@ +// This functions finds all primes smaller than 'limit' +// using simple sieve of eratosthenes. +void simpleSieve(int limit) +{ + // Create a boolean array "mark[0..limit-1]" and + // initialize all entries of it as true. A value + // in mark[p] will finally be false if 'p' is Not + // a prime, else true. + bool mark[limit]; + memset(mark, true, sizeof(mark)); + + // One by one traverse all numbers so that their + // multiples can be marked as composite. + for (int p=2; p*p