int sum = 0; //定义计算结果变量sum
int i = 1; //定义循环数字变量i
int flag = 1; //定义符号状态变量flag
//使用while循环
while(i<=100)
{
i++;
sum+=i*flag;
flag*=-1;
}
printf("sum=%d\n",sum);
i = 1; //重新初始化变量i
sum=-50;sum+=i*flag;flag*=-1