Сложение целых чисел - C#
Формулировка задачи:
Доброго времени суток!
Подскажите почему в строке 19 не верно выполняется последнее в цикле суммирование?
Результаты тестирования в принтскрине.
class Program
{
static void Main(string[] args)
{
int count;
count = int.Parse(Console.ReadLine());
int y = 0, a=count;
float x; //Пробовал long
double i = 0;
while((a/=10)>0)
{
i++;
}
y = count;
Console.WriteLine(y);
do
{
x = count % 10; y += (int)(x * Math.Pow(10, i+1));
Console.WriteLine("x=" + x);
Console.WriteLine("pribavit=" + (x * Math.Pow(10, i + 1)));
Console.WriteLine("y=" + y);
i++;
} while ((count /= 10) > 0);
Console.WriteLine("y="+y);
Console.ReadKey();
}
}Решение задачи: «Сложение целых чисел»
textual
Листинг программы
Console.Write("input n = ");
var n = int.Parse(Console.ReadLine());
var result = n * Math.Pow(10, (int)Math.Log10(n) + 1) + n;
Console.WriteLine($"result = {result}");