C# calculate sum of digits of a number

98

sum the digits in c# -

sum = 0;
while (n != 0) {
    sum += n % 10;
    n /= 10;
}

sum of digit of number c# -

int result = 17463.ToString().Sum(c => Convert.ToInt32(c));

Comments

Submit
0 Comments