// ************************************************************** // Scott R. Armstrong // June, 2003 // // No error checking is included to avoid errors caused by // non-numeric or negative input when prompted for a value. // // Programming environment: Borland C++, Version 5.5, Win32 // ************************************************************** #include // I/O preprocessor header file #include // Arithmetic int main() { // declaration of variables // bool prime, repeat; // char ch; int x, y, z, prime, repeat, true, false; z = 100000; // initialized for now - request user input true = 1; false = 0; repeat = true; // preset the boolean value while ( repeat ) { printf("\n"); printf("Prime Number Calculator\n"); printf("=======================\n"); //printf("Enter a positive integer: "\n); // input z here for ( y = 2; y <= z; y++) { prime = 1; x = 2; while ( (x <= y/2 ) && (prime == true) ) { if ((y % x) == 0 ) { prime = false; } else { x++; } } if (prime == true) { printf("%d", y); printf(" is a prime number.\n"); } } printf("\n"); printf("Do you want to continue (Y or N)? "); // repeat logic here repeat = false; // temp if ( !repeat ) printf("\nQuitting the Prime Number Calculator\n"); } // end of while loop return (0); }