How to count the digits of a number in C#

1 Answer

0 votes
using System;
 
namespace ConsoleApplication1
{
    public delegate void mydelegate();

    class Program
    {
        static void Main(string[] args)
        {
            int n = 1234;

            int count = 0;
            while (n != 0)
            {
                n = n / 10;
                count++;
            }
            Console.WriteLine(count);
        }
    }
}

/*
run:
     
4
        
*/

 



answered Apr 24, 2017 by avibootz

Related questions

1 answer 114 views
1 answer 114 views
2 answers 165 views
1 answer 136 views
1 answer 156 views
1 answer 171 views
1 answer 226 views
...