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();
        }
    }
Close

About The Author

Deependra Kushwah
Deependra kushwah is a member of the fastest growing bloggers community "betechnical", Author, Youtuber, and hardcore Coder. I love writing code in different languages, I also write blogs on tech tutorials, gadgets review and also post some technical videos on youtube on many topics.

This site uses Akismet to reduce spam. Learn how your comment data is processed.