# Sum of digits in C#

To do the sum of all digits in number in C#, we can loop while until the number is not 0 and do the modulo of the number 10, and divide the original number by 10, in other words we always get the rest of the division by 10 and replace current number with old number divided by 10.## Example

```
using System;
public class Program
{
public static void Main()
{
int number = 313;
int sum = 0;
while (number != 0) {
sum += number % 10;
number /= 10;
}
Console.WriteLine("Sum is {0}", sum);
}
}
```

### Output

Sum is 7