Sum of digits of a number

Ddd
Posted by Ddd under C# category on | Points: 40 | Views : 5457
//Sum of digits of a number

using System;

class digitsum
{
static void Main()
{
int num;
Console.WriteLine("please enter a number");
num=Convert.ToInt32(Console.ReadLine());
int sum=0;
while (num>0)
{
sum+=num%10;
num/=10;
}
Console.WriteLine("sum of the digits is"+"---"+sum);
}
}

Comments or Responses

Login to post response