when i run the program, the output will be like:
prime:3 prime:5 and so on. i didn't want the output will be like that.
i just want the output will be like this: (e.g., 3,5,7,11......).
thank you....
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- void prime_num(int);
- int main(void)
- {
- int n = 100;
- prime_num(n);
- }
- void prime_num( int n)
- {
- bool isPrime=true; //The Bool structure provides some basic operations on boolean values.
- for ( int k = 3; k <= n; k++)
- {
- for ( int r = 2; r <= n; r++)
- {
- if ( k!=r && k % r == 0 )
- {
- isPrime=false;
- break; // to stop looping
- }
- }
- if (isPrime)
- {
- cout << " Prime: " << k << ""; // To show the output
- }
- isPrime=true;
- }
- system("pause");
- }