C program to check whether a given number is Prime Number or not

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 

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share