I have a task to calculate sum of digits in C#. In this case as an example. I like to calculate the sum of "12345" which is: 1+2+3+4+5 = 15. But the result coming after the execution of code is: 53. What is the mistake in the code?
static void Main(string[] args)
{
string inputNumber = "12345";
int sum =0;
Console.WriteLine("Please Enter Your Desired Number");
for (int i = 0; i < 5; i++)
{
Console.WriteLine(inputNumber[i]);
sum = sum + Convert.ToInt32(inputNumber[i]);
Console.WriteLine(sum);
}
}