- 2
Why isnt it working?
11 Respostas
+ 5
It's working. your use break keyword. That's why your program stop when it printing 2.
+ 5
what the code is doing: it takes numbers in a range , and print all even numbers. but this are not the prime numbers. to see how you can get prime numbers, please use the search bar.
+ 4
https://code.sololearn.com/ctdW7O1x1MkI/?ref=app
+ 3
Ira Sarkar I see it's working
+ 3
see
+ 2
Milon
If you want to get the prime numbers, try to add an another for loop inside. Check if even, if it is then it is automatically not a prime number.
If not, iterate numbers from 3 to i then check if i is divisible by atleast one of those numbers. If it is, then it is not prime.
[ Syntax ] :
for (int i=3; i<300; i++) {
if (i%2 == 0) {
continue
}
for (int j=3; j<i; j++) {
if (i % j == 0)
continue
}
printf(...);
}
7
// the rest is up to you. btw i didnt include 2 inside as it is already a prime number (printed beforehand).
If you need more help, feel free to ask. Thanks.
0
Milon its not working.
0
Milon nope, it's not printing prime no.
0
Lothar yes,but I want to print prime nos