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