Find Sum of digits of provided number in C#

Amatya
Posted by Amatya under C# category on | Points: 40 | Views : 1516
In the below code the Number is coming from textbox of .asp page

 int Total = 0;
int FirstNumber = int.Parse(txtValue.Text);
int SecondNumber = FirstNumber;
while (SecondNumber > 0)
{
Total += (SecondNumber % 10);
SecondNumber /= 10;
}


Thanks
Amatya

Comments or Responses

Login to post response