How can I calculate divide and modulo for integers in C#?

前端 未结 5 1195
醉梦人生
醉梦人生 2020-12-01 11:28

How can I calculate division and modulo for integer numbers in C#?

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 12:17

    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 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
    

提交回复
热议问题