如何计算除法和模整数 [英] How can I calculate divide and modulo for integers
本文介绍了如何计算除法和模整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能计算除法和模数在C#中整数?
解决方案
问这样的问题之前,请检查的 MSDN文档。
当你把两个整数,结果始终是一个整数。例如,5/2的结果是2要确定的5/2余数,使用模运算符(%)。
块引用>int类型的= 5;
INT B = 3;中期息= A / B; //格为1
INT MOD =%A; // MOD为2How can I calculate division and modulo for integer numbers in c#?
解决方案Before asking questions of this kind, please check MSDN documentation.
When you divide two integers, the result is always an integer. For example, the result of 5 / 2 is 2. To determine the remainder of 5 / 2, use the modulo operator (%).
int a = 5; int b = 3; int div = a / b; //div is 1 int mod = a % b; //mod is 2
这篇关于如何计算除法和模整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文