----------------------------度娘的思路------------------------------------------------------
Action()
{ //實現1-2+3-4+5……+99-100的值
//20160802
int i,tag,sum;
sum=0;
tag=1;
for(i=1;i<=100;i++) {
sum+=i*tag;
tag=-tag;
}
lr_output_message ("%d\n",sum);
}
---------------------------分界:自己想-----------------------------------------------------
Action() {
//實現1-2+3-4+5……+99-100的值
int odd[50];
int even[50];
int sum_n;
int i1,i2;
int m=0,n=0;
int sum;
for(i1=1;i1<100;i1++){
odd[m]=i1;
m++;
i1++;
}
for(i2=-2;i2>=-100;i2--){
even[n]=i2;
n++;
i2--;
}
for(sum_n=0;sum_n<50;sum_n++){
sum+=odd[sum_n]+even[sum_n];
}
lr_output_message ("sum=%d",sum);
return 0;
}