Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to count digits of number in c#

//recursion
//input: 123
//output: 3           :)
static int CountDigits(int num, int count)
        {
            if (num == 0)
            {
                return count;
            }

            return CountDigits(num / 10, ++count);
        }
static void Main(string[] args)
        {
            Console.WriteLine(CountDigits(123, 0));
         }
 
PREVIOUS NEXT
Tagged: #count #digits #number
ADD COMMENT
Topic
Name
5+4 =