Advertisement
Shaun_B

Prime number demonstrator

Aug 8th, 2012
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. /**
  6.  * This is a simple program which will determine whether or not
  7.  * a user has entered a prime number.
  8.  *
  9.  * @Shaun B
  10.  * @1.0.0.1 - 2012-08-07
  11.  */
  12.  
  13. int main();
  14. static char run = 1;
  15. static int readNumber = 0;
  16.  
  17. int main()
  18. {
  19.     system("cls");
  20.     printf("Donkeysoft MMXII - this will determine whether or not\n");
  21.     printf("the number you enter is a prime or even number. Please\n");
  22.     printf("type in -1 to exit back to command line or 0 (zero) to\n");
  23.     printf("clear the console window.\n\n");
  24.     while (run)
  25.     {
  26.         printf("Please enter a whole (integer) number\n");
  27.         printf("C:\\>");
  28.         scanf("%d",&readNumber);
  29.         if (readNumber%2 == 0)
  30.         {
  31.             printf("The integer that you entered is an even number\n");
  32.         }
  33.         else
  34.         if ( (readNumber%2 != 0 && readNumber %3 != 0) || readNumber == 3)
  35.         {
  36.             printf("The integer that you entered is a prime number\n");
  37.         }
  38.         else
  39.         {
  40.             printf("The number is odd but not prime\n");
  41.         }
  42.         if (readNumber == 0 )
  43.         {
  44.             getchar();              // Clears keyboard buffer
  45.             printf("\nPress any key to clear the screen.\n");
  46.             getchar();              // Waits for keypress
  47.             system("cls");
  48.         }
  49.         if (readNumber == -1 )
  50.         {
  51.             printf("\n\nGood bye, have a nice day :-)\n");
  52.             run = 0;
  53.         }
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement