Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- /**
- * This is a simple program which will determine whether or not
- * a user has entered a prime number.
- *
- * @Shaun B
- * @1.0.0.1 - 2012-08-07
- */
- int main();
- static char run = 1;
- static int readNumber = 0;
- int main()
- {
- system("cls");
- printf("Donkeysoft MMXII - this will determine whether or not\n");
- printf("the number you enter is a prime or even number. Please\n");
- printf("type in -1 to exit back to command line or 0 (zero) to\n");
- printf("clear the console window.\n\n");
- while (run)
- {
- printf("Please enter a whole (integer) number\n");
- printf("C:\\>");
- scanf("%d",&readNumber);
- if (readNumber%2 == 0)
- {
- printf("The integer that you entered is an even number\n");
- }
- else
- if ( (readNumber%2 != 0 && readNumber %3 != 0) || readNumber == 3)
- {
- printf("The integer that you entered is a prime number\n");
- }
- else
- {
- printf("The number is odd but not prime\n");
- }
- if (readNumber == 0 )
- {
- getchar(); // Clears keyboard buffer
- printf("\nPress any key to clear the screen.\n");
- getchar(); // Waits for keypress
- system("cls");
- }
- if (readNumber == -1 )
- {
- printf("\n\nGood bye, have a nice day :-)\n");
- run = 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement