#include <iostream> using namespace std; void primeSieve(int n) { int prime[100]={0}; int cnt=0; for(int i=2;i<=n;i++) { if(prime[i]==0) { for(int j=i*i;j<=n;j+=i) { prime[j]=1; } } } cout<<"\nNumbers: "; for(int i=2;i<=n;i++) { if(prime[i]==0) { cout<<i<<" "; cnt++; } } cout<<"\nTotal prime numbers: "<<cnt; cout<<endl; } int main() { // cout << "Hello, World!"; int n; cin>>n; primeSieve(n); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter