C# Math.DivRem Method


Use the Math.DivRem method to calculate the quotient of two numbers and return the remainder.

Firstly, set dividend and divisor.

// dividend
long dividend = 30;
// divisor
long divisor = 7;

Now, use the DivRem method.

long quotient = Math.DivRem(dividend, divisor, out rem);

Example

 Live Demo

using System;
using System.Globalization;
class Demo {
   static void Main() {
      // remainder
      long rem;
      // dividend
      long dividend = 98;
      // divisor
      long divisor = 9;
      long quotient = Math.DivRem(dividend, divisor, out rem);
      Console.WriteLine("{0} \ {1} = {2} and remainder = {3}", dividend, divisor, quotient, rem);
   }
}

Output

98 \ 9 = 10 and remainder = 8

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

140 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements