我看了参考代码,但是为什么我觉得它是计算的2-3+4-5+6.....+100-101?我插了一句输出i,是从2开始的
#include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
i++;
printf("%d\n",i);
sum+=i*flag;
flag*=-1;
}
#include <stdio.h>
int main()
{
int sum = 0;
int i = 1;
int flag = 1;
while(i<=100)
{
i++;
printf("%d\n",i);
sum+=i*flag;
flag*=-1;
}
2021-03-03
举报