Created
May 6, 2013 20:38
-
-
Save rajdeep26/5528002 to your computer and use it in GitHub Desktop.
Write a function which takes two integers - 'nr' & 'dr' (numerator and denominator) as arguments and *returns* the remainder of the division. You are not allowed to use the built-in remainder operator(s) - %, divmod, etc.
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 FindRemainder(numerator,denominator) | |
if denominator > numerator | |
puts "#{numerator}" | |
else | |
result = denominator | |
i = 1 | |
while ((denominator*i)<=numerator) | |
result = denominator*i | |
i = i + 1 | |
end | |
puts "#{numerator-result}" | |
end | |
end | |
FindRemainder(5,2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment