P11 To count the number of digits in an integer

    class Program
    {
        static void Main(string[] args)
        {
            int n, count = 0;
            Console.Write("Enter the number : ");
            n = int.Parse(Console.ReadLine());
            while (n > 0)
            {
                count++;
                n = n / 10;
            }
            Console.WriteLine("The number of digits in the integer is " + count);
            Console.ReadLine();
        }
    }

Output : 





No comments:

Post a Comment