;

C# Program to Find the Sum of All the Digits


Tutorialsrack 11/08/2019 C# Programs

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:

Code - C# 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();
        }
    }
}
Output

Enter The Number: 55
Sum of the Given Digit is = 10


Related Posts



Comments

Recent Posts
Tags