Important Notice:

Test Whether a Number is Prime

Test Whether a Number is Prime

2 views 1 min read

Test Whether a Number is Prime (किसी Number के Prime होने की जाँच करना) :-

Question:-

Write an algorithm and flowchart to test whether a given number is prime or not.

किसी दिए गए Number के Prime या Not Prime होने की जाँच करने के लिए Algorithm और Flowchart लिखिए।

Example:

Input:
N = 7

Output:
7 is a Prime Number

Solution:- Algorithm:-

  1. Start
  2. Input a number N.
  3. Set COUNT = 0.
  4. Set i = 1.
  5. Check whether N % i == 0.
  6. If yes, set COUNT = COUNT + 1.
  7. Set i = i + 1.
  8. Repeat Steps 5 to 7 while i <= N.
  9. If COUNT == 2, display "Prime Number".
  10. Otherwise, display "Not a Prime Number".
  11. Stop.

Logic / Explanation

N % i == 0 → Check whether i is a factor of N.

COUNT = COUNT + 1 → Count the factors.

If COUNT == 2 → Number is Prime.

Otherwise → Number is Not Prime.

 

 

Related Notes