Write Program to Get a Number and Display the Sum of the Digits.
class Program
{
static void Main(string[] args)
{
int reminder, n,sum=0;
Console.WriteLine("Enter the number");
n = int.Parse(Console.ReadLine());
while(n>0)
{
reminder = n % 10;
n = n / 10;
sum = sum + reminder;
}
Console.WriteLine("Sum of the all given digit:{0}", sum);
Console.ReadLine();
}
}
Output:
No comments:
Post a Comment