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();
        }
    }
Catch us on social media

Author Profile

Deependra Kushwah
Deependra Kushwah
Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Deependra Kushwah

Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Leave a Reply

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

RSS
Facebook
Google+
https://betechnical.blog/2016/12/01/sum-of-digits-till-the-sum-is-one-digit-number">
Twitter
YouTube
Pinterest
Pinterest
LinkedIn
Instagram
%d bloggers like this: