在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