using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
int n = -1;
while (n < 0 || n > 1000)
{
Console.Write("Enter an integer between 0 and 1000: ");
n = int.Parse(Console.ReadLine());
}
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n / 10;
}
Console.WriteLine("The sum of the digits is : {0}", sum.ToString());
Console.ReadLine();
}
}
}
Comments
Leave a comment