不理解他是如何做到1-2+3-4……-100的“flag*=-1”.
#include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
sum+=i*flag;
i++;
flag*=-1;
}
printf("%d\n",sum);
}
结果是-50