Check Prime Number or not !

Program to check prime number :

Prime numbers are those which are divisible by itself or 1.  2 is an only even number which is a prime number.

Algorithm :

  1. Input a number, n
  2. If n==2
    print “Prime Number”
  3. Otherwise, Initialise loop variable, i=2
    while i<n/2
    if n%i=0, set ct=1 and break
    else
    i++;
  4. if ct=0
    print “Prime Number”
    otherwise
    print “Not a prime number”

Source Code :

Output :

Enter the Number : 24
24 is not a Prime Number.

Leave a Reply

Your email address will not be published. Required fields are marked *