+ 4
How to write a program can know if the number prime or not by c++
Question
3 Respostas
+ 7
The logic is very simple.
First of all ask yourself what makes realy a prime number or what is the condition for a prime number, so the answer will be if it is divisible by 1 and itself only.
For example, 3 is a prime number as it is divisible by 1 and itself only. No other number can completely divide it(remainder = 0 when divide).
So, the logic will be quite simple.
Start with a bit conditions that can be applied on numbers regarding its prime number criteria. Apply a loop whose value will start from 2 and go to x-1(here x is the main number entered by the user). If the number is divisible by any of the numbers in this loop, then it is not a prime number else if the loop ends and no number divides it completely then it simply means that it is a prime number.
Please note that : negative numbers should not be included and 1 is neither a prime number or a composite number.
Hope it helps:)
+ 6
https://www.programiz.com/cpp-programming/examples/prime-number
https://www.sololearn.com/discuss/1532773/?ref=app
https://www.sololearn.com/discuss/1728940/?ref=app
https://www.sololearn.com/discuss/1717405/?ref=app
https://www.sololearn.com/discuss/1616786/?ref=app
https://www.sololearn.com/discuss/1759622/?ref=app
https://www.sololearn.com/discuss/1554184/?ref=app
https://www.sololearn.com/discuss/1482185/?ref=app
+ 6
https://code.sololearn.com/c2s7rm0jni1z/?ref=app
https://code.sololearn.com/cI2wnAbW05C4/?ref=app