#include <iostream>
usingnamespace std;
int main ()
{
int i, j;
for(i=2; i<100; i++)
{
for(j=2; j <= (i/j); j++)
if(!(i%j)) break; // if factor found, not prime
if(j > (i/j)) cout << i << " is prime\n";
}
return 0;
}
I want to know the logic and how to flow of control processes the program.
#include <iostream>
usingnamespace std;
int main ()
{
int
i = 0,
j = 0; // Get in the habit of initializing all variables!
for( i = 2; i < 100; i++ )
{
for( j = 2; j <= ( i / j ); j++ )
{
if( ! ( i % j ) )
break; // if factor found, not prime
} /* The second "for" loop */
if( j > ( i / j ) )
cout << i << " is prime\n";
} /* The first "for" loop */
return 0;
}
/* main() */
This should be easier to read. Now if you can't figure it out, please come back and ask your questions again.