Recursive Digit Sum

  • + 0 comments

    C#:

    public static int superDigit(string n, int k)
        {
            do
            {
                long sum = 0;
                foreach(char c in n)
                {
                    sum += int.Parse(c.ToString());
                }
                sum *= k;
                k=1;
                n = sum.ToString();
            }while(n.Count()!=1);
            
            return int.Parse(n);
        }