C# 中的 Math.DivRem() 方法
C# 中的 Math.DivRem() 方法用于对两个数进行除法运算,将商值存储到输出参数中,同时将余数作为返回值。
语法
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP