Divisible By 11
Anonymous
csharp
12/26/2022 5:51 PM
572 B
21
Indexable
public static int DivisibleBy11(int number)
{
var numbers = number.ToString().ToCharArray();
int coupleCount = 0, oddCount = 0;
for (int i = 0; i < numbers.Length; i++)
{
if (i % 2 == 0) coupleCount += numbers[i] - '0';
else oddCount += numbers[i] - '0';
}
return coupleCount - oddCount;
}Editor is loading...