Ques: Write a C# program to display the sum of digit of the number entered by User
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, sum = 0, m;
Console.Write("Enter a Number");
n = int.Parse(Console.ReadLine());
while(n>0)
{
m = n % 10;
sum = sum + m;
n = n / 10;
}
Console.Write("Sum = " + sum);
Console.ReadKey();
}
}
}
If you learned from this post share with others. Happy Sharing!
0 Comments