为什么跑出来是负的?
int x = 1;
int sum = 0;//和,初始化为0
while (x <= 100000)//循环条件
{
if (x % 2 != 0)//筛选条件
sum += x;
x++;
}
Console.Write("1-100000奇数的和:" + sum);
int x = 1;
int sum = 0;//和,初始化为0
while (x <= 100000)//循环条件
{
if (x % 2 != 0)//筛选条件
sum += x;
x++;
}
Console.Write("1-100000奇数的和:" + sum);
2018-06-15
举报