Can anyone help me with a simple program that can specify if a number is prime or not.....using while loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Can anyone help me with a simple program that can specify if a number is prime or not.....using while loop

specifying if a number is prime or not using while loop

19th Jun 2018, 12:37 PM
QALIFAH
QALIFAH - avatar
5 Answers
+ 8
The basic algorithm for primality test is trial division. Given the number N, Using a while loop, divide N from 2 to square root of N. If any of the number has a zero remainder against N, that means N is composite. Otherwise, it is prime.
19th Jun 2018, 12:55 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 4
Algorithm:- Step 1:- start Step 2:- read n or any number from user Step 3:- initialise counter = 2,overflow=0 Step 4:- while(counter < n) if counter mod n = 0 ,then overflow=1 goto step 6 Step 5:- counter =counter + 1 Loop step 4 & 5 till counter < n Step 6:- if overflow = 1 then print number n not prime else print number n is prime step 7:- Stop
19th Jun 2018, 1:43 PM
D-Key
D-Key - avatar
+ 1
19th Jun 2018, 1:04 PM
KrOW
KrOW - avatar
- 1
😂 KrOW yeah
7th Jul 2019, 8:11 AM
Charan Leo25
Charan Leo25 - avatar