为什么i++; sum+=flag*i;这两个顺序不一样,结果却一样?
#include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
i++;
sum+=flag*i;
flag*=-1;
}
printf("sum=%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
i++;
sum+=flag*i;
flag*=-1;
}
printf("sum=%d\n",sum);
return 0;
}
2020-02-15
举报