Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Created January 18, 2014 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ph3nx/8491227 to your computer and use it in GitHub Desktop.
Save ph3nx/8491227 to your computer and use it in GitHub Desktop.
Ruby program that prints a multiplication table for numbers up to your input. For example 12 x 12 fields.
def tbl max
for y in (1..max) do
for x in (1..max) do
sol = y*x
if sol < 10
print "#{sol} "
elsif sol < 100
print "#{sol} "
else
print "#{sol} "
end
end
print "\n"
end
end
@ph3nx
Copy link
Author

ph3nx commented Jan 18, 2014

tbl 23 is the maximum to fit in the windows PowerShell window.

@mlyubarskyy
Copy link

print (x*y).to_s.center(5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment