//this is a mine...sieve's algorithm implementation please tell me where i am going wrong...//
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a,b,p;
vector<int> v;
cin>>a>>b;
for(int i=a;i<=b;i++)
v.push_back(i);//inserting all values upto given limit in a vector..
for(p=2;(p*p)<=b;p++)
{
for(int n=2;(n*p)<=b;n++)
{
int s=(n*p);
v.erase(v.begin()+s);//erase all multiples of 2,3....from vector
}
}
for(int i=0;i<v.size();i++)
cout<<v[i]<<endl;
}
yogesh_6
0
Newbie Poster
Tumlee
42
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.