使用 Math.DivRem 方法计算两个数的商并返回余数。
首先,设置被除数和除数。
// dividend long dividend = 30; // divisor long divisor = 7;
现在,使用 DivRem 方法。
long quotient = Math.DivRem(dividend, divisor, out rem);
示例
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);
}
}
输出
98 \ 9 = 10 and remainder = 8
相关用法
- C# Math.DivRem()用法及代码示例
- C# Math.Floor()用法及代码示例
- C# Math.Max()用法及代码示例
- C# Math.Round()函数用法及代码示例
- C# Math.Atan()用法及代码示例
- C# Math.IEEERemainder()用法及代码示例
- C# Math.BigMul()用法及代码示例
- C# Math.Abs()方法用法及代码示例
- C# Math.Cosh()用法及代码示例
- C# Math.Ceiling()用法及代码示例
- C# Math.Round()方法用法及代码示例
- C# Math.Sign()用法及代码示例
- C# Math.Log()用法及代码示例
- C# Math.Min()用法及代码示例
- C# Math.Acos()用法及代码示例
- C# Math.Abs()函数用法及代码示例
- C# Math.Log10()用法及代码示例
- C# Math.Sqrt()用法及代码示例
- C# Math.Cos()用法及代码示例
- C# Math.Atan2()用法及代码示例
注:本文由纯净天空筛选整理自Karthikeya Boyini大神的英文原创作品 C# Math.DivRem Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。