Answer to Question #266080 in C# for Sai

Question #266080

Arjun wants to count total number of digits of an integer number (N).Help him to generate the programme for the same.





1
Expert's answer
2021-11-14T17:02:04-0500
using System;

namespace Test
{
    class CountTest
    {
        static int Main()
        {
            int number;
            Console.Write("Input integer: ");
            string line = Console.ReadLine();

                if(!int.TryParse(line, out number))
                {
                    Console.WriteLine("Bad input");
                    return 1;
                }

            if(number == 0)
            {
                Console.WriteLine("Total number of digits is {0}", 1);
            }
            else
            {
                int digits = 0;

                while(number != 0)
                {
                    digits++;
                    number /= 10;
                }

                Console.WriteLine("Total number of digits is {0}", digits);
            }

            return 0;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS