Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int n, i, j, a[1000];
- cout<<"Enter The Limit = ";
- cin>>n;
- for(i=1; i<=n; i++)
- {
- a[i]=i;
- }
- for(i=2; i<=n; i++)
- {
- if(a[i] != -1)
- {
- for(j=2*i; j<=n; j=j+i)
- a[j]= -1 ;
- }
- }
- cout<<"Prime numbers = ";
- for(i=2; i<=n; i++)
- {
- if(a[i] != -1)
- cout<<" "<< i ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement