Created
February 27, 2019 03:41
-
-
Save khpatel4991/1f0b7c8e69501e76879e5a751f50473a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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