Sunday, 25 March 2018

Program to find sum of the digits of a number in c #


//Program to find sum of the digits of the number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cs5
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, sum = 0, rem;
            Console.WriteLine("Enter any number");
            n = int.Parse(Console.ReadLine());
            while (n != 0)
            {
                rem = n % 10;
                n = n / 10;
                sum = sum + rem;
            }
            Console.WriteLine("Sum of the digits of the entered number="+sum);
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.