C# BigInteger DivRem

Description

BigInteger DivRem Divides one BigInteger value by another, returns the result, and returns the remainder in an output parameter.

Syntax

BigInteger.DivRem has the following syntax.


public static BigInteger DivRem(
  BigInteger dividend,//from  w  w w .  j  a  v  a  2s. c  om
  BigInteger divisor,
  out BigInteger remainder
)

Parameters

BigInteger.DivRem has the following parameters.

  • dividend - The value to be divided.
  • divisor - The value to divide by.
  • remainder - When this method returns, contains a BigInteger value that represents the remainder from the division. This parameter is passed uninitialized.

Returns

BigInteger.DivRem method returns The quotient of the division.

Example


/*ww  w  . j  a  va 2 s .c  om*/
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      BigInteger divisor = BigInteger.Pow(Int64.MaxValue, 2);

      BigInteger[] dividends = {BigInteger.One, 
                                 BigInteger.Multiply(Int32.MaxValue, Int64.MaxValue),
                                 divisor + BigInteger.One };

      foreach (BigInteger dividend in dividends)
      {
         BigInteger quotient;
         BigInteger remainder = 0;

         quotient = BigInteger.DivRem(dividend, divisor, out remainder);
         Console.WriteLine("   Using DivRem method:     {0:N0}, remainder {1:N0}", 
                           quotient, remainder);

      }            
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex