Last active
January 26, 2016 14:43
-
-
Save mistrikushal/09b4929860422183118a to your computer and use it in GitHub Desktop.
multiply 2 numbers without X operator
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
# perform multiplication on 'a' and 'b' without using X operator | |
def mul(a, b) | |
x = 0 | |
b.times do | |
x = x + a | |
end | |
puts "Multiplication of #{a.to_s} X #{b.to_s} = #{x.to_s}" | |
end | |
mul(4, 4) | |
# output 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment