0

Hi everyone this is my first post on these forums and I hope that someone can clear up a simple question for me...Right now I am reading Ivor Horton's Beginning Visual c++ 2008 and in chapter four he gives an example program for finding prime numbers using pointers and a simple algorithm. I understand the program and I even rewrote the part that I didn't understand and it still works now. But I have a question regarding 3 lines of code in his version, I don't fully understand what they are doing. I hope someone can clear this up. Here goes...

```
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
int _tmain(int argc, _TCHAR* argv[])
{
const int MAX = 100;
long primes[MAX] = {2,3,5};
long trial = 5;
int count = 3;
int found = 0;
do
{
trial +=2;
found = 0;
for(int i = 0; i < count; i++)
{
found = (trial % *(primes + i)) == 0;
if(found)
break;
/* Heres how I rewrote it
found = (trial % *(primes + i));
if(found == 0)
{
found =1;
break;
}
else
found = 0;
*/
}
if (found == 0)
*(primes + count++) = trial;
}while(count < MAX);
for(int i = 0; i < MAX; i++)
{
if(i % 5 == 0)
cout << endl;
cout << setw(10) << *(primes + i);
}
cout << endl;
return 0;
}
```