Algorithm to check whether the given number is prime or not.

Write an algorithm to check whether the given number is prime or not.


1.Start

2.Read the number num

3.[Initialize]

    i=2 , flag=1

4. repeat steps 4 through 6 until i < num or flag=0

5.rem=num mod i

6.if rem=0 then

flag=0

 else

    i=i+1

7.if flag=0 then
   
              Print number is not Prime

     else
              Print number is prime

8. Stop

0 comments:

Post a Comment