diff --git a/SeiveOfEratosthenes.cpp b/SeiveOfEratosthenes.cpp new file mode 100644 index 0000000..0c9c2aa --- /dev/null +++ b/SeiveOfEratosthenes.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +void SeiveOfEratosthenes ( int n){ + int arr[n+1] = {0}; + + for( int i = 2; i*i <= n; i++){ + if( arr[i] == 0){ + for( int j = i*i; j <= n; j += i ) + arr[j] = 1; + } + } + + for (int i = 2; i<=n; i++){ + if(arr[i] == 0) + cout << i << " "; + } + +} + + +int main(){ + int n = 100; + cout << "The prime numbers smaller than or equal to " << n << " are : "<