-
-
Save anonymous/ee33ec3e1661a4408103 to your computer and use it in GitHub Desktop.
/r/ruby question
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 pow(base, exponent) | |
result = 1 | |
i = 1 | |
while i <= exponent | |
result = result * base | |
i += 1 | |
end | |
result | |
end | |
puts "2 raised to the power 4 is..." | |
puts pow(2, 4) | |
puts "7 raised to the power 2 is..." | |
puts pow(7, 2) | |
# >> 2 raised to the power 4 is... | |
# >> 16 | |
# >> 7 raised to the power 2 is... | |
# >> 49 |
johnjansen
commented
Sep 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment