Algorithm to find whether a Number is Prime Number or Not

[196076 views]



What is a Prime Number?

A number that's only divisible by 1 and itself is named a Prime Number. For Example, 3, 5, 7, 11 are Prime Numbers.
Note: 2 is the only even prime number.

Flowchart for Prime Number:

FlowChart for Prime Number Algorithm

Algorithm for Prime Number:

Step 1: Start Step 2: Initialize variables num,flag=1, j=2 Step 3: Read num from user Step 4: If num<=1 // Any number less than 1 is not a prime number Display "num is not a prime number" Goto step 7 Step 5: Repeat the steps until j<[(n/2)+1] 5.1 If remainder of number divide j equals to 0, Set flag=0 Goto step 6 5.2 j=j+1 Step 6: If flag==0, Display num+" is not prime number" Else Display num+" n is prime number" Step 7: Stop

Prime Number program in Python


Javascript Program to Check whether Number is Prime or Not

        




Getting any Errors while coding? Ask us on our new Forum:




Liked Article? Please Buy Author a Coffee


Comments

3 comment
  • Danny

    To me it looks that there is an error in th flowchart. If a divisor can be found N , it is not a prime, thus...

  • Danny

    To me it looks that there is an error in the flowchart. If a divisor can be found candidate N , N it is not a prime, thus... when flag is set to ZERO, it is not a prime...

  • Umme roshan ara

    Thank u sir / mam it is very useful for me thanks a lot



Search
For Sponsored Advertisement OR Freelance Programming Article Submission, Contact us at [email protected]
Recommended Deal Ends in











Quizzes:
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Why does everyone hate Java?
How much JavaScript to learn for Web Development
How to Convert EPOCH to Date in Java
Search Tags

    Verify if a number is Prime Number or not Algorithm

    Pseudocode to find whether a Number is Prime Number or Not

    Algorithm for Prime Number Checking

    Check if a number is prime number or not