Write a C# program to find the sum of digits

How to find the sum of digit in C#. In the below example another way to find the some of digit in C#.

Input sample:




Sum of digits program in C#

using System;


namespace CSharpProgram


    class Program


        static void Main(string[] args)


            //Define variables

            int num, sum = 0, m;

            Console.Write("Enter a number to find the sum of digits: ");

            num = int.Parse(Console.ReadLine());

            while (num > 0)


                m = num % 10;

                sum = sum + m;

                num = num / 10;


            Console.Write("Total sum= " + sum);






More C# program with example

Find Fibonacci series in C# 

Check prime number in C#


Leave a Reply

Your email address will not be published.