Every Prime number has two factors and these are 1 and the number itself. If N is Prime Number then its factors will be 1 and N. Thus a Prime Number is divisible by 1 and itself. Example of Prime Numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43 and so on. The smallest Prime Number is 2 and it is an Even Number. Except 2 all Prime Numbers are Odd Numbers.

## ALGORITHM TO CHECK PRIME NUMBER

**(Check Prime Number)** Let N be a Positive Integer. The Number N will be a Prime Number if it is only divisible by 1 and N. If N is divisible by one or more numbers other than 1 and N then it will not be Prime Number. Since a number is always divisible by 1 and itself. Thus in this algorithm N is divided by 2 then 3 then 4 till N – 1. If N is divisible by any number form 2 to N – 1 then is not a Prime Number. Otherwise it is a Prime Number.

Step 1: Start

Step 2: [ Take Input ] Read: N

Step 3: [ Initializing Counter and Boolean Variable ] Set: I = 2 and Flag = 0

Step 4: Repeat this step While I < N

Check If N%I == 0 Then

Set: Flag = 1 and Break the Loop

[ End of If Structure ]

[ Incrementing Counter ] Compute: I++

[ End of While Loop ]

Step 5: Check If Flag == 1 Then

Print: N is not a Prime Number.

Else

Print: N is a Prime Number.

[ End of If Else Structure ]

Step 6: Exit

### FLOWCHART TO CHECK PRIME NUMBER

## ALGORITHM TO GENERATE PRIME NUMBERS

**(Generate Prime Numbers)** Since the smallest Prime number is 2 therefore the Lower Limit (LL) of the range will start from 2. And the Upper Limit (UL) of the range will be given by the user. Since 2 is already a Prime number therefore the series will start from 2. If the value LL is not a Prime number then it will not be printed. Thus value stored in LL will be increased by 1 after end of each loop. The above process will continue untill value of LL is not equal to value of UL.

Step 1: Start

Step 2: [ Take Input For Range ] Read: UL

Step 3: Set: LL = 2

Step 4: Repeat While while LL ≠ UL

Step 4a: Set: N = LL, Flag = 0 and I = 2

Step 4b: Repeat While I < N

Check If N%I == 0 Then

Set: Flag = 1 and Break the Inner while Loop

[ End of If structure ]

Compute: I++ [ Incrementing Counter ]

[ End of Inner While Loop ]

Step 4c: Ckeck If Flag == 0 Then

Print: N

[ End of If structure ]

Step 4d: Compute: LL = LL + 1 [ Incrementing Lower Range ]

[ End of Outer While Loop ]

Step 5: Exit