Write a c# program to print sum of digits.
using System; public class SumOfDigits { public static void Main(string[] args) { int number, digit, sum = 0; Console.WriteLine("Enter a number: "); number = int.Parse(Console.ReadLine()); while (number > 0) { digit = number % 10; sum += digit; number /= 10; } Console.WriteLine("The sum of the digits of the number is: " + sum); } }
Write a c# program to print sum of digits.
Reviewed by Bhaumik Patel
on
9:28 PM
Rating: