Skip to content

Instantly share code, notes, and snippets.

@rajdeep26
Created May 6, 2013 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajdeep26/5528002 to your computer and use it in GitHub Desktop.
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.
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