Ad
  • Default User Avatar

    This is absolutely clever but I think it can be hard to read. Also, I think you could have added constants so you don't end up with magic numbers that the next person won't know what they're for.

  • Default User Avatar

    Because we are dealing with integers, C# division or modulus by zero already throws a DivideByZeroException. There's no need to explicitly build and throw one. If we were using floats or doubles, we would get one of the infinities (or in the case of 0.0 / 0.0 or 0.0 % 0.0, NaN) as a result and would need to do further work to handle that.

  • Default User Avatar

    For c# this solution actually includes the dividebyZeroException that was asked