using System; class Program { static void Main(string[] args) { double n = Math.Pow(2.00, 12.00); long howMuch = 0; SumOfDigits sod = new SumOfDigits(); for (int i = 0; i < n; ++i) { int SumI = sod.CountSumOfDigits(i); if (SumI % 4 == 0) { howMuch++; } } Console.WriteLine(howMuch); //Console.WriteLine(n); Console.ReadLine(); } } class SumOfDigits { public int CountSumOfDigits(int x) { int sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; } }
Answers & Comments
using System;
class Program { static void Main(string[] args) { double n = Math.Pow(2.00, 12.00); long howMuch = 0;
SumOfDigits sod = new SumOfDigits(); for (int i = 0; i < n; ++i) { int SumI = sod.CountSumOfDigits(i);
if (SumI % 4 == 0) { howMuch++; } } Console.WriteLine(howMuch); //Console.WriteLine(n); Console.ReadLine(); } } class SumOfDigits { public int CountSumOfDigits(int x) { int sum = 0; while (x > 0) {
sum += x % 10; x /= 10; } return sum; } }