# prime chec kin c snippet in c

## prime chec kin c

user8903

``````int isPrime(long long number) {

if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
return 0;
}

else {
for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
if (number % i == 0) {
return 0;
}
}
return 1;
}
}``````

## prime number in c

user7035

``````// C program to check if a
// number is prime

#include <stdio.h>
#include<math.h>
int main()
{
int n, i, flag = 1;

// Ask user for input
printf("Enter a number: \n");

// Store input number in a variable
scanf("%d", &n);

// Iterate from 2 to n/2
for (i = 2; i <= sqrt(n); i++) {

// If n is divisible by any number between
// 2 and n/2, it is not prime
if (n % i == 0) {
flag = 0;
break;
}
}

if(n<=1)
flag=0;
else if(n==2)
flag=1;

if (flag == 1) {
printf("%d is a prime number", n);
}
else {
printf("%d is not a prime number", n);
}

return 0;
}
``````

## prime number c

user7762

``````#include <stdio.h>
int main()
{
int i, num, p = 0;
printf("Please enter a number: \n");
scanf("%d", &num);
for(i=1; i<=num; i++)
{
if(num%i==0)
{
p++;
}
}
if(p==2)
{
printf("Entered number is %d "\
"and it is a prime number.",num);
}
else
{
printf("Entered number is %d "\
"and it is not a prime number.",num);
}
}
``````