# C program to checkwhether a given number isPrime Number ornot

## Check whether a number is Prime number or not

This page has C programs to check whether a given number is Prime or not. Prime number is always a positive Integer number. The Prime number can only be divisible by 1 and the number itself. If a positive integer is divisible by the same number and 1, then the number is called prime number. If not (If a number has more positive divisors other than 1 and the number itself), then the number is not called Prime number.  A few Prime number examples: 19, 23, 29, 31, 37, 41, 43, 47, 53. The below given C program to check whether a given number is Prime Number or not. The given number can be checked in many ways to find whether the number belongs to prime number or not. In this page, I have used two techniques to check the number whether it belongs to prime or not. Kindly check out the programs to check whether a given number is Prime Number or not.The Prime or not program can be asked in different ways for school and college going students.

To check Prime or not, the question can be asked as, 1). Find out a Prime number using C program.  2). C program to verify whether a given number is Prime or not.  3). C Program to check whether an integer number is Prime or not.  4). C Program to check whether a positive number is Prime or not.  5). C Program to find whether the entered number is Prime or not.

### Prime Number or not Checking Program

#include<stdio.h>
int main(){
int nrprime,k,primeflag=0;
printf(" Enter a number to check prime or not : ");
scanf("%d",&nrprime);
for(k=2;k<=nrprime/2;k++)
{
if((nrprime % k) == 0)
{
primeflag++;
break;
}
}
if((primeflag==0) && (nrprime!= 1))
printf("\n %d is a prime number",nrprime);
else
printf("\n %d is not a prime number",nrprime);
return 0;
}

Sample output:

Enter a number to check prime or not :  17

17 is a prime number

Enter a number to check prime or not :   25

25 is not a prime number