+ 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
5 Respuestas
+ 26
Have a look at this solutions:
https://code.sololearn.com/c4oZ7z269B30/?ref=app
https://code.sololearn.com/cMp381Jb6q3h/?ref=app
+ 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.
+ 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
+ 1
BMT Dont create same question threads
https://www.sololearn.com/discuss/1356151/?ref=app
- 1
😂 KrOW yeah