All pastes #812238 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-11 16:50 UTC
rendered paste body
// Ed's prime number checker

#include <iostream>
using namespace std;

bool prime(int input, int max) // Function to check if the input is prime
{
    int result;  
    int n = 2;        
    while(n < (input -1) ) {   
         result = input % n;  
         if (result = 0) { return false; n += input + 1;} else { ++n; } // I'm not prime because I divide cleanly
                           }
    if (n = input ) { return true; } // If I get as far as here I must be prime
}

int main()
{
    int max; 
    cout << "Enter max: ";
    cin >> max; // Get user input
    int input = 3; // Start from three
    cout << "2 is prime\n"; // To avoid confusion
    while (input != max + 1) {    // as long as the input is less than the max + 1 i.e
         bool end = prime(input, max); 
                if (end = false) { cout << input << " is not prime\n"; }
                else { cout << input << " is prime\n";}
                input++;     }      
return 0;
}