In this C# program, we will learn how to write a program to find the sum of all the digits.
Here is the code of the program to find the sum of all the digits:
using System;
namespace TutorialsrackPrograms
{
class Program
{
//C# Program to Find the Sum of All the Digits.
static void Main(string[] args)
{
int number, sum = 0, mod;
Console.Write("Enter The Number: ");
number = int.Parse(Console.ReadLine());
while (number > 0)
{
mod = number % 10;
sum = sum + mod;
number = number / 10;
}
Console.Write("Sum of the Given Digit is = " + sum);
Console.Read();
}
}
}
Enter The Number: 55
Sum of the Given Digit is = 10
Comments