Checking prime number What is Prime number? Prime numbers are those numbers which can only be divisible by itself or 1 puts "Enter the number:" Output Enter the number: Enter the number:
num=gets.chomp.to_i
count=0
if (num==0)
puts "0 is not prime"
else
i=2
while(i<num)
if (num%i==0)
count+=1
end
i+=1
end
end
if count>1
puts "#{num} is not a prime number"
else
puts "#{num} is a prime number"
end
2
2 is a prime number
11
11 is a prime number
How to add/remove elements to Array in Ruby?
Creating Array with Array.new(size, obj) in Ruby
Ruby program to check whether the given number is prime or not
how to create an array with Array.[](*args) in Ruby ?
What are the various Ruby runtimes, and how are they different?
Ruby program to print Fibonacci series
What are #method_missing and #send? Why are they useful?
Ruby program to add two integer numbers
What's the difference between a lambda, a block and a proc?
How to Replace array elements in Ruby?
Ruby program to Calculate the factorial of given number
Ruby program to reverse a string
How to Get Input with Gets in Ruby
Ruby program to check whether the given number is Armstrong
Ruby program to check whether the given number is palindrome
How to create two dimensional array in ruby?
What are some of your favorite gems? What are their alternatives?
Ruby program to print an array
Program to Print Triangle of Numbers in Ruby
How to Sort Array in Ruby?
How to shuffle an array in Ruby?
How to get index of array element in Ruby
Ruby program to generate random numbers