int num = 123; int sum = 0; while(num > 0) { sum += number % 10; num /= 10; } Console.WriteLine(sum); // output: 6