Sum of digits in C#
What's the fastest and easiest to read implementation of calculating the sum of digits? I.e. Given the number: 17463 = 1 + 7 + 4 + 6 + 3 = 21 ...
What's the fastest and easiest to read implementation of calculating the sum of digits? I.e. Given the number: 17463 = 1 + 7 + 4 + 6 + 3 = 21 ...
Simple "sum of digits" code. Compiles but when executed, the last cout gives a "0" for the num int rather than the actual user-input number. Feel free to c&p into your own compiler, if you're so inclined, to see what I mean. How can I get this to output the correct "num" value? Thank you! ~~~ #include <iostream> using namespace st...
Link to the original problem It's not a homework question. I just thought that someone might know a real solution to this problem. I was on a programming contest back in 2004, and there was this problem: Given n, find sum of digits of n!. n can be from 0 to 10000. Time limit: 1 second. I think there was up to 100 numbers for each t...
What is the algorithm in c# to do this? Example 1: Given n = 972, function will then append 3 to make 9723, because 9 + 7 + 2 + 3 = 21 (ends with 1). Function should return 3. Example 2: Given n = 33, function will then append 5 to make 335, because 3 + 3 + 5 = 11 (ends with 1). Function should return 5. ...