Console Application with few tasks [closed]

I feel taking risk to answer your question but what the hack..

“refactor” his digits like that: hundreds, tens, ones.

int i = 123, reverse = 0;
while (i > 0)
{
    reverse = (reverse * 10) + (i % 10);
    i /= 10;
}
Console.WriteLine(reverse); //321

sum of all 3 digits (ex. if the number is 123 then it will be 6)

int i = 123, total = 0;
while (i > 0)
{
    total += i % 10;
    i /= 10;
}
Console.WriteLine(total); //6

Thanks but it’s not what i meant by saying ‘refactor’. For instance,
for the input 389 it’ll print this: Hundreds: 3 Tens: 8 Ones: 9

int i = 389, houndreds = 0, tens = 0, ones = 0;

ones = i%10;
i /= 10;
tens = i%10;
i /= 10;
houndreds = i%10;

Console.WriteLine("Hundreds: {0} Tens: {1} Ones: {2}", houndreds, tens, ones); //Hundreds: 3 Tens: 8 Ones: 9

Leave a Comment