# get numbers contrary to complex number

Hello, i want to get a new idea from a key to get a complex number
For ex) there's numbers (1~10)
i want to get numbers except complex
so i wanna get numbers 4,6,8,9,10
i was trying to get

for(i in 1:10) {
+     check = 0
+         for(j in 1:i) {
+             if(i%%j==0) {
+     check = check + 1 }
+             if(check<2) {
+     break()
+     }
+     }
+             if(check>2) {
+     print(i)
+     }
+     }

But answer was 10. i don't know what happens... can you tell me the right solution?
Thank you

I think you are looking for composite numbers e.g.numbers that are not prime. I only need to change one thing in your code for it to work. Your code will always stop the loop because the check starts at 0 and might increment to 1 but will never get to 2 because you break the loop if check < 2 but it should be check > 2

# Your method with just some formatting changes
for (i in 1:10) {
check = 0
for (j in 1:i) {
if (i %% j == 0) {
check = check + 1
}
if (check < 2) {
break()
}
}
if (check > 2) {
print(i)
}
}

for (i in 1:10) {
check = 0
for (j in 1:i) {
if (i %% j == 0) {
check = check + 1
}
if (check > 2) { #changed this inequality sign direction
break()
}
}
if (check > 2) {
print(i)
}
}
#> [1] 4
#> [1] 6
#> [1] 8
#> [1] 9
#> [1] 10

Created on 2019-12-12 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.