Ok, this snippet of code should print 30 prime numbers in ascending order, which it does (code gotten from Borland's Library "Eratosthenes"). BUT it only prints out "1,2,5,7....113" (totally forgets the 3 and the 1 is hardcoded).
if (s==4)
{
RichEdit1->Lines->Insert(0,1);
const int sievesize = 125;
vector<int,allocator<int> > sieve(sievesize, 1);
for (int i = 2; i * i < sievesize; i++)
if (sieve[i])
for (int j = i + i; j < sievesize; j += i)
sieve[j] = 0;
for (int j = 2; j < sievesize; j++)
if (sieve[j])
RichEdit1->Lines->Add(j++);
}
And this snippet of code prints out prime numbers in descending order. BUT it only prints out "113...7,5,3,1" (totally dropping off the 2).
if (s==5)
{
RichEdit1->Lines->Insert(MAX,1);
const int sievesize = 125;
vector<int,allocator<int> > sieve(sievesize, 1);
for (int i = 2; i * i < sievesize; i++)
if (sieve[i])
for (int j = i + i; j < sievesize; j += i)
sieve[j] = 0;
for (int j=sievesize-1; j>0; j--)
if (sieve[j])
RichEdit1->Lines->Add(j--);
}
}
Someone please take a look at this and tell me what I'm missing. Thanks for your help!!!