C# has a built-in Math
class that provides useful mathematical functions and operations. The class has the DivRem()
function, which is used to compute the quotient and remainder of two specified numbers.
This function returns the quotient of two numbers and also calculates the remainder in an output parameter:
DivRem (type param1, type param2, type out remainder);
where:
param1
: the dividendparam2
: the divisorremainder
: the output parameter which stores the remainder of DivRem()
public static long DivRem (long param1, long param2, out long remainder);
public static int DivRem (int param1, int param2, out int remainder);
using System;class HelloWorld{static void Main(){int quotient, rem;quotient = Math.DivRem(5,3,out rem);System.Console.WriteLine("Quotient=" + quotient);System.Console.WriteLine("Remainder="+rem);}}