Entrez un nombre et renvoyez vrai s'il s'agit d'un nombre premier, faux s'il ne s'agit pas d'un nombre premier.
while str = STDIN.gets
  break if str.chomp == "exit"
n=str.to_i
count=0
for i in 1..n+1 do
    d=n%i
    if d==0 then
        count+=1
    end
end
if count==2 then
    print("true")
else
    print("false")
end
puts "\n"
end
20 octobre 2020
Recommended Posts