algorithm - Sum of digits in C# -


what's fastest , easiest read implementation of calculating sum of digits?

i.e. given number: 17463 = 1 + 7 + 4 + 6 + 3 = 21

you arithmetically, without using string:

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

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -