1int isPrime(long long number) {
2
3 if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
4 return 0;
5 }
6
7 else {
8 for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
9 if (number % i == 0) {
10 return 0;
11 }
12 }
13 return 1;
14 }
15}
1#include<stdio.h>
2main() {
3 int n, i, count=0;
4 printf("Enter Number");
5 scanf("%d",&n);
6
7 for ( i = 1; i<= n; i++) {
8 if (n % i == 1) {
9 count++;
10 }
11 }
12 if( count == 2) {
13 printf("Prime Number");
14 }
15 else {
16 printf("Not A Prime Number");
17 }
18}
1#include <stdio.h>
2int main() {
3 int n, i, flag = 0;
4 printf("Enter a positive integer: ");
5 scanf("%d", &n);
6
7 for (i = 2; i <= n / 2; ++i) {
8
9 // condition for non-prime
10 if (n % i == 0) {
11 flag = 1;
12 break;
13 }
14 }
15
16 if (n == 1) {
17 printf("1 is neither prime nor composite.");
18 }
19 else {
20 if (flag == 0)
21 printf("%d is a prime number.", n);
22 else
23 printf("%d is not a prime number.", n);
24 }
25
26 return 0;
27}
28
1int isPrime(int n) {
2 for (int i = 2; i < n; i++) if (n % i == 0) return 0;
3 return 1;
4}
1//program to find prime number or not using c programming
2#include<stdio.h>
3#include<conio.h>
4 void main(){
5 int n;
6 int prime=1;
7 printf("Enter the number\n");
8 scanf("%d",&n);
9 for (int i= 2; i<n; i++){
10 if(n%i==0){
11 prime=0;
12 break;
13 }
14 }
15 if(prime==0 ){
16 printf(" %d is not prime number.\n",n);
17 }
18 else{
19 printf(" %d is prime number\n",n);
20 }
21
22 getch();
23 }
1//program to find prime number or not using c programming
2#include<stdio.h>
3#include<conio.h>
4// program starts from here after main() function
5 void main(){
6 int n;
7 int i,count =0;
8 // count is incremented when the loop is true.
9 printf("Enter the number\n");
10 scanf("%d",&n);
11 for (i=1; i<=n; i++){
12 if(n%i==0){
13 count++;
14 }
15 }
16 // for the prime number the no of count is 2
17 // number is divided by 1 or itself(given number) so count ==2
18 if(count ==2){
19 printf("%d is prime number.\n",n);
20 }
21
22 // for the composite number the number is divided by more than 2 number.
23 else{
24 printf("%d is not prime number\n",n);
25 }
26
27 getch();
28 }
29