Performs integer division on two BigInteger values and returns the remainder. : BigInteger « Data Types « C# / C Sharp






Performs integer division on two BigInteger values and returns the remainder.

 


using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      BigInteger dividend1 = 1;
      BigInteger dividend2 = 2;
      BigInteger divisor1 = 3;
      BigInteger divisor2 = 4;
      BigInteger remainder1, remainder2;
      BigInteger divRem1 = BigInteger.Zero;
      BigInteger divRem2 = BigInteger.Zero;

      remainder1 = BigInteger.Remainder(dividend1, divisor1);
      remainder2 = BigInteger.Remainder(dividend2, divisor1);

      BigInteger.DivRem(dividend1, divisor1, out divRem1);
      Console.WriteLine("BigInteger.Remainder({0}, {1}) = {2}", 
                        dividend1, divisor1, remainder1);
      Console.WriteLine("BigInteger.DivRem({0}, {1}) = {2}", 
                        dividend1, divisor1, divRem1);                    
      if (remainder1.Equals(divRem1))
         Console.WriteLine("The remainders are equal.\n");

      BigInteger.DivRem(dividend2, divisor2, out divRem2);
      Console.WriteLine("BigInteger.Remainder({0}, {1}) = {2}", 
                        dividend2, divisor2, remainder2);
      Console.WriteLine("BigInteger.DivRem({0}, {1}) = {2}", 
                        dividend2, divisor2, divRem2);                    
      if (remainder2.Equals(divRem2))
         Console.WriteLine("The remainders are equal.\n");
   }
}

   
  








Related examples in the same category

1.Create BigInteger using the values in a byte array.
2.Instantiate BigInteger values
3.Initializes a new instance of the BigInteger structure using a Decimal value.
4.Divides one BigInteger value by another, returns the result, and returns the remainder in an output parameter.
5.Finds the greatest common divisor of two BigInteger values.
6.Increments a BigInteger value by 1.
7.Shifts a BigInteger value a specified number of bits to the left.
8.Returns the natural (base e) logarithm of a specified number.
9.Returns the larger of two BigInteger values.
10.Returns the smaller of two BigInteger values.
11.Performs modulus division on a number raised to the power of another number.
12.Converts the string representation of a number to its BigInteger equivalent.
13.Converts string in a specified culture-specific format to BigInteger
14.NumberFormatInfo and BigIntegerParse
15.Converts string in a specified style to BigInteger
16.NumberStyles and BigInteger parse
17.Raises a BigInteger value to the power of a specified value.
18.Converts a BigInteger value to a byte array.
19.Converts BigInteger to string using the specified culture-specific formatting information.
20.Converts BigInteger to string using the specified format.
21.Converts BigInteger to string using culture-specific format information.
22.Converts BigInteger to string with ToString method
23.Tries to convert string to BigInteger
24.Tries to convert string in style and culture-specific format to BigInteger
25.NumberStyles and TryParse
26.Negates a specified BigInteger value.
27.Defines an explicit conversion of a BigInteger object to an unsigned byte value.