Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() // prime number checker
- {
- int a, b, c;
- int check = 0;
- printf("Enter a positive number to check if it's prime: ");
- scanf("%d", &a);
- if (a == 2 || a == 3)
- check = 1;
- else if (a % 2 == 0)
- check = 0;
- else
- {
- for (b = 2; b <= a / 2; b++)
- {
- if (a % b == 0)
- {
- check = 0;
- b = a / 2;
- }
- else
- check = 1;
- }
- }
- if (check == 1)
- printf("This number is prime.\n");
- else
- printf("This number is not prime.\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement