Sum of digits till the sum is one-digit number

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest

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();
        }
    }
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on whatsapp
Share on email
Author Bio

Leave a Reply

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

Recommended for you
Connect With Us
Stay Connected

Subscribe to our newsletter today to receive updates on latest tech news, tutorials SEO tips many more.

Latest Articles

Free hub for guest blogging nerds and newbie writers

  • Submit Guest Post
  • Share your Knowledge
  • Build your Backlinks
  • Advertise your products
  • Make money by writing
Subscribe to our newsletter today to receive updates on latest tech news, tutorials SEO tips many more.