如何在 C# 中计算整数的除法和模数? [英] How can I calculate divide and modulo for integers in C#?
本文介绍了如何在 C# 中计算整数的除法和模数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 C# 中计算整数的除法和模数?
How can I calculate division and modulo for integer numbers in C#?
推荐答案
这是来自 MSDN 文档.
两个整数相除,结果总是整数.例如,7/3 的结果是 2.要确定 7/3 的余数,请使用余数运算符 (%).
When you divide two integers, the result is always an integer. For example, the result of 7 / 3 is 2. To determine the remainder of 7 / 3, use the remainder operator (%).
int a = 5;
int b = 3;
int div = a / b; //quotient is 1
int mod = a % b; //remainder is 2
这篇关于如何在 C# 中计算整数的除法和模数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文