Skip to content

Instantly share code, notes, and snippets.

@khpatel4991
Created February 27, 2019 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khpatel4991/1f0b7c8e69501e76879e5a751f50473a to your computer and use it in GitHub Desktop.
Save khpatel4991/1f0b7c8e69501e76879e5a751f50473a to your computer and use it in GitHub Desktop.
def is_prime(num)
i = 2
while(i <= Math.sqrt(num))
return false if num % i === 0
i = i + 1
end
true
end
def print_table(num)
print "\n\rTable for: #{num}: "
(1..10).map { |i| num * i }.each { |i| print "#{i} " }
end
def print_prime_multiplication_table(num)
count = 0
tmp = 2
while(count < num)
if(is_prime(tmp))
print_table(tmp)
count = count + 1
end
tmp = tmp + 1
end
end
n = ARGV[0].to_i || 10
print_prime_multiplication_table n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment