Again multiplication Tables uh? ;)


Hai Friends,

Still i remember, When i was studying 3rd std., daily at the night time(bed timing) My dad  asked me, tell the from 2 table to 10th table(i.e literally increased) 😦 🙂 But now, In my ruby class, sir asked me, “write a program for all tables” 😮
At starting, i struggled then, with help of my sir, i finished that program. 😉 After seeing my result i went into mu childhood remembrances.

The Code is,

# The Multiplication table
=begin
Program name: multiplication.rb
Date written: 18-12-2010
Date modified: 20-12-2010
Author: Tha.Suresh
Licence: LPGL
=end

# Main part of the starts here

range_array = [1..6,7..12,13..18,19..24,25..30,31..36,37..42,43..48,49..54,55..60,61..66]

def format_till_6(iterator,range)
string=''
for counter in range
string = string +"%2d"%iterator+" X "+"%2d"%counter+" = "+"%3d  "%(iterator*counter)
end
return string
end

def iteration_code(range)
for iterator in 1..12 do
print format_till_6(iterator,range)
puts
end
end
range_array.each do |each_range|
iteration_code(each_range)
puts
end

Advertisements

2 thoughts on “Again multiplication Tables uh? ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s