Addition of numbers
// Add all digits
Console.WriteLine("Enter a number to get sum of all digits");
int a = int.Parse(Console.ReadLine());
int i = 0;
int j = a;
for (; a != 0; a = a / 10)
{
j = a % 10;
i = i + j;
}
Console.WriteLine(i);
Console.ReadLine();
No comments:
Post a Comment