为什么最后还有个-50
#include <stdio.h>
int main()
{
int flag = 1;
int sum = 0;
for (int a = 1; a <= 100; a++) {
sum += (a*flag);
printf("%d\n", a * flag);
flag *= -1;
}
printf("%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int flag = 1;
int sum = 0;
for (int a = 1; a <= 100; a++) {
sum += (a*flag);
printf("%d\n", a * flag);
flag *= -1;
}
printf("%d\n",sum);
return 0;
}
2022-07-04
举报