using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace get_number_of_digits_in_an_integer
{
class Program
{
public static int GetDigits(int
number, int digits)
{
if (number == 0)
{
return digits == 0 ? 1 : digits;
}
return GetDigits(number / 10, ++digits);
}
static void Main(string[] args)
{
int number;
Console.WriteLine("Enter
number:");
number = int.Parse(Console.ReadLine());
int result = GetDigits(number, 0);
Console.WriteLine("number
of digits :{0}", result);
Console.ReadLine();
}
}
}
OUTPUT
No comments:
Post a Comment