C language-100 addition and subtraction, C language-100 summation
---------------------------- Du Niang idea ------------------------------------------------------
Action ()
{// Implement 1-2 + 3-4 + 5 ...... + 99-100 Value
// 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 );
}
--------------------------- Division: You want -----------------------------------------------------
Action (){
// Implement 1-2 + 3-4 + 5 ...... + 99-100 Value
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;
}