Divisible By 11
unknown
csharp
3 years ago
413 B
9
Indexable
public static int DivisibleBy11(int number)
{
var numbers = number.ToString();
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...