Sum of digits till the sum is one-digit number

2016-06-27 (4) 

public  class SumtillDigitOne
    {
        private  long _sum = 0;
        public  long SumAllNumberTillDigitOne(long bigno)
        {
            if (bigno == 0)
            {
                if (_sum > 9)
                {
                    bigno = _sum;
                    _sum = 0;
                }
                else
                {
                    return _sum;
                }

            }
            _sum += bigno%10;
            bigno = bigno/10;
            return SumAllNumberTillDigitOne(bigno);
        }
    }
  class Program
    {
        private static void Main(string[] args)
        {
            var number = new SumtillDigitOne().SumAllNumberTillDigitOne(8147118963);
            Console.WriteLine(number);
            Console.ReadKey();
        }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s