在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