判断i是否为偶数,若是则i的为负值,代码逻辑没错,运行不出来是什么问题?代码附上
#include <stdio.h>
int main(){
int sum=0;
int i=1;
int flag=1;
while(i<=100){
i++;
if(i%2==0){
i=-i;
}
sum +=i;
}
i=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++;
if(i%2==0){
i=-i;
}
sum +=i;
}
i=1;
printf("sum=%d\n",sum);
return 0;
}
2020-07-21
举报