#include<iostream>
using namespace std;
void SieveOfEratosthenes(int n) {
    bool prime[n+1];
    for (int i=0;i<n+1;i++) 
     prime[i]=true;
     for (int p=2;p*p<=n; p++) {
        if (prime[p]==true) {
           for (int i=p*2;i<=n;i+=p)
              prime [i]=false; 
           }
      }
    for(int p=2;p<=n; p++){
    if (prime [p])
      cout<< p<< " ";
    }
}
int main(void) {
   int n=30;
    cout<<" following are the prime numbers smaller"
          <<"than or equal to" <<n <<endl;
          SieveOfEratosthenes(n);
return 0;
}
