C#中的Math.DivRem()方法
茶Math.DivRem()C#中的方法用于除法和计算两个数的商,并在输出参数中返回余数。
语法
public static int DivRem (int dividend, int divisor, out int remainder); public static long DivRem (long dividend, long divisor, long remainder);
现在让我们看一个示例来实现Math.DivRem()方法-
示例
using System; public class Demo { public static void Main(){ int dividend = 30; int divisor = 7; int remainder; int quotient = Math.DivRem(dividend, divisor, out remainder); Console.WriteLine("Quotient = "+quotient); Console.WriteLine("Remainder = "+remainder); } }输出结果
这将产生以下输出-
Quotient = 4 Remainder = 2
让我们看看另一个实现的例子Math.DivRem()方法-
示例
using System; public class Demo { public static void Main(){ long dividend = 767676765765765; long divisor = 7; long remainder; long quotient = Math.DivRem(dividend, divisor, out remainder); Console.WriteLine("Quotient = "+quotient); Console.WriteLine("Remainder = "+remainder); } }输出结果
这将产生以下输出-
Quotient = 109668109395109 Remainder = 2