Calculation of 1-2 + 3-4 + 5-6 + 7-8 + 9-10 + 11-12 ........ M result is how much? , Face questions.

I recently a series of interview questions in more classic, the moment you see the results of the harvest it?

1. Calculate 1-2 + 3-4 + 5-6 + 7-8 + 9-10 + 11-12 ........ M result is how much? , Face questions.

#include<stdio.h>

main ()
{
int I = 0, J = 0, K = 0, SUM = 0;
the printf ( "Calculation 5-6 + 1-2 + 3-4 + 7-8 + 9-10 + 11-12 .. the results ...... M is the number of \ the n-\ the n-\ the n-? ");
the while (1)
{
i = 0, J = 0, k = 0, SUM = 0;
printf (" Please enter your want values: ");
Scanf ("% D ", & J);
for (I =. 1; I <= J; I ++)
{
IF (I% 2 == 0)
SUM = SUM-I;
the else
SUM = SUM + I ;
}
the printf ( "D evaluates% \ n-", SUM);
}

}

//1-2+3-4+5-6+7-8+9-10+11-12.......M

 

 

In fact, you can see that from the result of the operation, the results of even-numbered obtained directly.

 

The even itself divided by two, plus a minus sign, is the result.

(Odd itself +1) by 2, the result is calculated.

 

I hope you gain something right, very classic, maths Pa skip directly to the blind BB, ha ha ha, I was his brother.

 

Guess you like

Origin www.cnblogs.com/qianrushi1/p/11593911.html