C# Program to input the Number and display the sum of the Digits


This program in C# developed using .NET Framework 4.5 and Visual Studio 2013 will demonstrate how to get the input as number and find the sum of digits of the number and display it in the console window.

C# Program to input the Number and display the sum of the Digits

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GinktageConsoleApp
    internal class Program
        private static void Main(string[] args)
            int input;
            int result = 0, temp;
            Console.WriteLine("Enter the Number : ");
            input = int.Parse(Console.ReadLine());
            while (input != 0)
                temp = input % 10;

                input = input / 10;

                result += temp;

            Console.WriteLine("Sum of Digits of theInput Number is " + result);


Output of the program

Enter the Number :
Sum of Digits of theInput Number is 10

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


Interesting BlogPosts to read

How to quickly remove multiple line breaks in Excel using VBA code?
There are times when you might copy few data from different source and you would end up getting unne...
How to change orientation of the worksheets in Microsoft Excel ?
This blog post will show the steps that are needed to change the orientation of the current workshee...
How to hide page breaks in worksheets in Microsoft Excel ?
When the page breaks is used to adjust the print area in a worksheet in excel , this would show up a...