C programming
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
Number is Prime or Not in C
17 January
1
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
Your Affiliate Money Making Machine is ready -
ReplyDeleteAnd 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