Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language problem! !
C language problem! !
The result of shaping 1/i is also shaping. For example, if the quotient of 1/2 is 0 and the remainder is 1, then the remainder will be discarded, so 1/i is in i >; 1 The results are all 0.

If 1.0 and 1.0 are real numbers, the calculation result is also real numbers, and the decimal point will be retained.

Change it to float i, and when judging whether I is equal to n, such as n= 100, it becomes judging whether/kloc-0 100.000000 is equal to 100 and so on. Because the internal storage of real numbers is in the form of a x 2^n, float a= 100 may actually be 99.9999.

If you find1-1/3+1/5-1/7, you can write a program like this:

int i,n= 100,tmp =- 1;

Floating sum;

for(I = 1; I & ltn;; i++)

{

tmp * =- 1;

sum+= 1.0/(2 * I- 1)* tmp;

}