Skip to content

Commit 79c69c8

Browse files
authored
Gives Prime Numbers
This program gives all the prime numbers till the given number.
1 parent 99c64a3 commit 79c69c8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

prime number

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n, count=0;
7+
cin>>n;
8+
9+
bool a[n+1];
10+
a[0] = false;
11+
a[1] = false;
12+
for( int i=2; i<n; i++ )
13+
a[i] = true;
14+
15+
for( int i=2; i*i<=n; i++ )
16+
{
17+
if( a[i]==true){
18+
for( int j=i*i; j<=n; j+=i )
19+
{
20+
a[j] = false;
21+
}
22+
}
23+
}
24+
25+
for( int i=0; i<n; i++ )
26+
{
27+
if(a[i]==true)
28+
cout<<i<<" ";
29+
}
30+
return 0;
31+
}

0 commit comments

Comments
 (0)