c++ - Program to display prime numbers -


i have make function uses 2 referenced inputs display prime numbers between 2 numbers, inputs called imin, , imax , part of code given

cout << "primes:"; (int j = imin; j <= imax; j++) {     if (is_prime(j))     {          cout << "  " << j;     } } 

which supposed supplemented our self written function , part made below

bool is_prime( int j) {     bool primes(false);     (int k = 2; k < j; k++)     {                 if (j%k == 0) // if (k mod j == 0)         {              primes = true;         }         else if (j%k !=0)         {             primes = false;         }     }     return true; } 

i need in making display prime numbers because right displaying of numbers. i'm new specific enough.

the last line of function: return true

will return true whether or not number prime, why numbers displayed. if pass number 'n' argument is_prime(n), return true.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -