Arjun wants to count total number of digits of an integer number (N).Help him to generate the programme for the same.
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;
}
}
}
Comments
Leave a comment