All pastes #944463 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-03-16 02:59 UTC
rendered paste body
#include <iostream>

// Robert Gleeson
// List prime numbers from 2 til user's choice.

using namespace std;
int main()

	{
int max; // store the user's input.
bool isPrime; // variable to store the truth/false if a number is prime or not.

cout << "Please enter a number I should list prime numbers up to : ";
cin >> max;

for (int i = 0; i <= max; i++) // loop through 0 to max.
	{
for (int divider = 2; divider <= max; divider++) // loop through divider(2) to max.
{
if ( i == 0 || i == 1 ) // escape 0 or 1, as they are not prime numbers.
	{
isPrime = false; // set isPrime to false.
break;
	}

if( i != divider &&  i % divider == 0) // not a prime number ! 
{
isPrime = false; // set isPrime to false(not a prime number).
}

}
if(isPrime)
{
cout << i << endl; // print prime numbers.
}

isPrime = true; // set isPrime to true, must be a prime number!
	}

	}