# Answer to Question #17547 in C++ for islam saad

Question #17547

i need the answer for this equation ..thanks S=1-2+3-4+5... +-n

Expert's answer

void f(int n)

{

intsum = 0 ;

for(int i = 1; i < n; i++){

if(i%2 != 0) {

sum+= i;

}else sum-=i;

}

cout<< sum << endl;

}

{

intsum = 0 ;

for(int i = 1; i < n; i++){

if(i%2 != 0) {

sum+= i;

}else sum-=i;

}

cout<< sum << endl;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment