Number is Prime or Not in C - 👑 सार्थक मुंड S3 🤴🏻

Number is Prime or Not in C

Number is Prime or Not in C

Number is Prime or Not in C 

#include <stdio.h>
int main() {
    int n, i, flag = 0;
    printf("Enter a positive Number :\n ");
    scanf("%d", &n);
    for (i = 2; i <= n / 2; ++i) {
        // condition for non-prime
        if (n % i == 0) {
            flag = 1;
            break;
        }
    }
    if (n == 1) {
        printf("1 is neither prime nor composite");
    }
    else {
        if (flag == 0)
            printf("%d is a prime number", n);
        else
            printf("%d is not a prime number", n);
    }
    return 0;
}
OUTPUT :
Enter a positive Number :
 23
23 is a prime number
Previous article
Next article

1 Comments

  1. Your Affiliate Money Making Machine is ready -

    And getting it set up is as simple as 1...2...3!

    This is how it works...

    STEP 1. Choose affiliate products you want to promote
    STEP 2. Add PUSH button traffic (it ONLY takes 2 minutes)
    STEP 3. See how the affiliate products system explode your list and sell your affiliate products on it's own!

    Are you ready to make money automatically??

    Click here to launch the system

    ReplyDelete

Articles Ads

Articles Ads 1

Articles Ads 2

Advertisement Ads