Advertisement
yigitusta9

Prime Number Checker

Oct 6th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main() // prime number checker
  5. {
  6.     int a, b, c;
  7.     int check = 0;
  8.  
  9.     printf("Enter a positive number to check if it's prime: ");
  10.     scanf("%d", &a);
  11.  
  12.     if (a == 2 || a == 3)
  13.         check = 1;
  14.     else if (a % 2 == 0)
  15.         check = 0;
  16.     else
  17.     {
  18.         for (b = 2; b <= a / 2; b++)
  19.         {
  20.             if (a % b == 0)
  21.             {
  22.                 check = 0;
  23.                 b = a / 2;
  24.             }
  25.             else
  26.                 check = 1;
  27.         }
  28.  
  29.     }
  30.  
  31.     if (check == 1)
  32.         printf("This number is prime.\n");
  33.     else
  34.         printf("This number is not prime.\n");
  35.  
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement