Skip to content

Instantly share code, notes, and snippets.

@vajapravin
Created June 3, 2019 15:12
Show Gist options
  • Save vajapravin/bd5b4fb957f33be834cd40c096f5ce34 to your computer and use it in GitHub Desktop.
Save vajapravin/bd5b4fb957f33be834cd40c096f5ce34 to your computer and use it in GitHub Desktop.
class PrimeNumber
def initialize
print 'Enter number: '
@num = gets.to_i
@primes = []
end
def generate
for i in (2..(@num**2)) do
for j in (2..i) do
break if i%j == 0
end
@primes << i if i.eql?(j)
break if @primes.length.eql?(@num)
end
end
def display
for i in (0..@num-1) do
for j in (0..@num-1) do
print "#{@primes[i]+@primes[j]} "
end
puts
end
end
end
p = PrimeNumber.new
p.generate
p.display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment