Skip to content

Commit

Permalink
Merge pull request #491 from sarvesh259/patch-2
Browse files Browse the repository at this point in the history
Create Sieve of Eratosthenes.cpp
  • Loading branch information
fineanmol authored Oct 3, 2021
2 parents e987c48 + dd3a355 commit 4170abe
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
using namespace std;
void sot (int n)
{
int prime[n]={0};
for(int i=2;i<=n;i++)
{
if(prime[i]==0)
{
for(int j=i*i;j<=n;j+=i)
{
prime[j]=1;
}
}
}
for(int i=2;i<=n;i++)
{
if(prime[i]==0)
{
cout<<i<<" ";
}
}
}
int main()
{
int n;
cin>>n;
sot(n);
return 0;
}

0 comments on commit 4170abe

Please sign in to comment.