All pastes #953678 Raw Edit

Someone

public text v1 · immutable
#953678 ·published 2008-03-23 06:47 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 << "Prime = " << i << endl;
	}

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

}