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

No comments:
Post a Comment