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;
}