温馨提示×

c#求余数的方法是什么

c#
小亿
571
2024-04-15 15:25:04
栏目: 编程语言

在C#中,可以使用取模运算符“%”来求余数。例如,可以使用以下代码来计算10除以3的余数:

int dividend = 10;
int divisor = 3;
int remainder = dividend % divisor;
Console.WriteLine("The remainder of {0} divided by {1} is {2}", dividend, divisor, remainder);

输出为:

The remainder of 10 divided by 3 is 1

0