• SQL Kiwi (9/21/2012)


    This is about twice as fast for me:

    ...

    public static int SumDigits(int Input)

    {

    int sum = 0;

    for (int n = System.Math.Abs(Input); n > 0; sum += n % 10, n /= 10) ;

    return sum;

    }

    ...

    Another way in c# :

    public static int SumDigits(int Input) { return Input.ToString().Sum(c => c - '0'); }

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]