My code is as follows. If I remove the last end
, it says unexpected end of input
, if I put the end
back in, it says unexpected keyword end
. I cannot see anything wrong with the following code. Can you?
n = gets.chomp.to_i
array= Array.new(n, true)
while p<Math::sqrt(n) do
i=p
while (i<=n) do
array[i] = false # not a prime
i+=p
end
while array[p]!=true do
p++
end
end
The increment operator (++
):
p++
does not exists in Ruby. You meant:
p += 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With