Divisible By 11

mail@pastecode.io avatar
unknown
csharp
2 years ago
413 B
2
Indexable
Never
        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;
        }