如何在循环中最后加上所有数字并求和?

时间:2019-12-10 00:08:34

标签: c#

Console.Write("write a number: ");
double num = Int32.Parse(Console.ReadLine());
double sum = 0;

while (num != 0)
{
    Console.Write("write a number: ");
    num = Int32.Parse(Console.ReadLine());

    if (num > 0)
    {
        sum = num + num;
    }
}

Console.Write("sum= " + sum);
Console.ReadKey();

0 个答案:

没有答案