Sum of digits program in C#
C# Programming Language Loop control in C# Language (Article) Loop control in C# Language (Program)
221Program:
using System; public class SumExample { public 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 is= "+sum); } }
Output:
Output 1: Enter a number: 23 Sum is= 5 Output 2: Enter a number: 624 Sum is= 12
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C# Programming Language. Then you can visit below links to get more depth on this subject.