+ 2

Prime number...

hello there! I have a problem with my code, Im trying to give my best but I have already spent 40 minutes on solving this, but I still can't find a good way... As a title says - prime number... https://pastebin.com/VXcFkhh3 <- here's the code (C++) I just want to know where I made a mistake while writing if() statement and how to do it right. I do not expect written code, thanks in advance :)

14th Feb 2018, 12:29 PM
Adam
Adam - avatar
2 Respostas
+ 9
check this java version i think you like!! https://code.sololearn.com/c8KCZTNWXzC8/?ref=app
15th Feb 2018, 6:43 PM
ASIF BILAKHIYA
ASIF BILAKHIYA - avatar
+ 2
The first way checks to see whether the number divided by one is equal to itself (which is true for every number) and if the number divided by itself is equal to itself (which is only true for 1). To check whether or not it's a prime number you must use a for loop, not an if statement, and the % operator.
14th Feb 2018, 12:54 PM
Vlad Serbu
Vlad Serbu - avatar