数字を入力して素数ならtrue、素数じゃなかったらfalseを返す。
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
Register as a new user and use Qiita more conveniently