an algorithm to check prime number
An algorithm to check prime number
- A number that is divisible only by itself and 1, is prime number
- Example of prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23…. etc
Algorithm
Step 1: Start Step 2: Declare variables n,i,flag. Step 3: Initialize variables flag←1 i←2 Step 4: Read n from user. Step 5: Repeat the steps until i<(n/2) 5.1 If remainder of n÷i equals 0 flag←0 Go to step 6 5.2 i←i+1 Step 6: If flag=0 Display n is not prime else Display n is prime Step 7: Stop